Ideally it would be good for the main for to have a stop method, that is
called on exiting the application, which has handles to all the threads.
This method sets the flag to false (as you have here) then waits for a
period for the threads to exit by checking their running state.
The threads are then responsible for checking the running state of the flag
after every couple of seconds, and if it is false, then stop running.
"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Solved it :
:
In my thread i check the active form.
if (Form.ActiveForm==null)
running=false;
So i don't have to shutdown the threads explicit from my main application.
"Dan Bass" <Not Listed> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl... The way I usually approach this is to have a static thread safe class
which contains a "still running" type flag that all spawned threads often
check,
and which the main thread is able to set.
I'd recommend checking out Jon Skeet's threading pages for more
information...
http://www.yoda.arachsys.com/csharp/threads/
Thanks.
Dan.
"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:O%****************@TK2MSFTNGP09.phx.gbl... > Hi
>
> If i have a form application that creates a thread, is there a way to
> detect
> from within that thread if i have closed the form ?
>
> Now i use the forms closing event to end the thread i started, but i would > like to do it automatcally so i do not have to worry about any threads
> that
> remain active after i closed the form.
>
>
> Johan
>
>
>