Here's the thing.. I've been looking into this for 2 days and haven't find something on the net about that ( maybe I'm not looking at the right places ).

I'm writing a VB application that is watching a directory. As soon as a file gets in the directory, it is processed. While looking in the directory, it is in wait mode.

There's a button start and a button stop on the form. The start button start the process of watching the directory. Still I want to let the user stop it. So far so good.

But the thing is when you click stop It goes in cmdStop_click ( ) which is fine. In that I can stop all the waiting processes ( destroy the handles on it ) ..

The problem is that I go back in the sub where I was waiting. Is there any way that when you click stop it destroys the handle for the wait and then get out of the Sub where I was waiting ?

If you don't understand here's a little example


Sub cmdstart_click ()

' Code before wait
do while ret = WAIT_TIMEOUT
do events
ret = waitforsingleobject(handle)
' code get back here after stop but could get
' back anywhere after or before the wait..
' I just want to get out of that sub once it
' click stop. Don't wanna use a go to unless
' there are no other option
loop

' code after wait

End sub

sub cmdStop_click()

' Kill handles on wait objects

' Need to get out of caller.
end sub




Thanks in advance

Nicolas