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.