Results 1 to 28 of 28

Thread: Please explain why these are two 'No No !' commands.

Hybrid View

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Please explain why these are two 'No No !' commands.

    Quote Originally Posted by dunfiddlin View Post
    Ok I've no idea what the purpose of F(3) and F(4) is in the wider context but don't those two loops do exactly the same job, ie. determine whether 'Neutron' is running? And do you really want to hold up the program in its entirety when it is?
    The two loops look the same but have different purposes, I first check that 'Neutron' is running, and then that it's completed. I've already done that with 'Diary', originally with F(0) and F(1). I need to know that each program has actually started before I can check that it's completed and move on to the next part of the project.

    The original significance of F(0) to F(5) was to ensure the next event wasn't called until the previous one had completed, and to facilitate the 'running commentary' I mentioned in my first post. My re-hash made that redundant so I've now just changed the 'Flag' to a single Boolean and toggle the True / False test for each subsequent check.


    Quote Originally Posted by Shaggy Hiker View Post
    DoEvents isn't so bad, but the busy wait certainly is. By spinning around a DoEvents like that you are accomplishing nothing, but you certainly aren't doing nothing.
    ...the simplest solution is probably to get rid of the timer and the busy wait and just call Thread.Sleep(5000). Normally, you wouldn't want to do that, as it would freeze the app for five seconds. Nothing would happen, no events, no drawing, nothing. But that may be exactly what you want. The one drawback is that it wouldn't paint the screen, either, so if you dragged something else across the form it would just look white.
    I was never really happy with using 'DoEvents' in a loop like that, but in VB3.0 it seemed to work ok and it just got 'carried over'.
    As you guess, the fact that the app is 'frozen' during the Wait Loops is of little moment because the form isn't even visible, the programs which have been called during them still work as they ought.

    I liked the idea of removing the timer altogether, which I did and replaced it as you suggested with the (actually) ' Threading.Thread.Sleep(5000) ' command, this did prevent the painting of the message, but using just one 'DoEvents' before calling 'Sleep' solved that.

    Having done that and tested it and found that everything still worked correctly, I removed the 'End' statement and re-tested but the program still just continued totally without regard to the 'Me.Close'...

    I then tried the 'System.Windows.Forms.Application.Exit' suggested by two of the other replies, that too failed to close the program. I've gone back to my original close down method.
    The problem only occurs when I test for errors, when I simulate an 'already running' error, I get the error message ok, but as soon as the message clears, when the program should close, a second instance of the running program is started.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Please explain why these are two 'No No !' commands.

    Quote Originally Posted by Poppa Mintin View Post
    ...

    Having done that and tested it and found that everything still worked correctly, I removed the 'End' statement and re-tested but the program still just continued totally without regard to the 'Me.Close'...

    I then tried the 'System.Windows.Forms.Application.Exit' suggested by two of the other replies, that too failed to close the program. I've gone back to my original close down method.
    The problem only occurs when I test for errors, when I simulate an 'already running' error, I get the error message ok, but as soon as the message clears, when the program should close, a second instance of the running program is started.

    Poppa.
    If the application isn't closing properly when you expect it to (using me.close or Application.Exit) then you have a coding problem.

    [DoEvents - it's a legacy when threading was not available to VB. It's not necessary, today, and is very easy to abuse. It's a kludge that helps perpetuate VB as a 'toy' language].
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  3. #3

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Please explain why these are two 'No No !' commands.

    Quote Originally Posted by Poppa Mintin View Post
    I then tried the 'System.Windows.Forms.Application.Exit' suggested by two of the other replies, that too failed to close the program. I've gone back to my original close down method.
    Poppa.
    When I tried this, I typed in the whole of 'System.Windows.Forms.Application.Exit' I guess that was the error.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width