Killing all thread when closing applications.

M

muscha

Hi,

I spawns a number of background threads while creating a windows forms
application. I noticed that when I quit the application or calling
Application.Exit, it hasn't really stop. Is there a quick way to say
"terminate all threads and quit"?

thanks,

/m
 
V

Vladimir Bezugly

I spawns a number of background threads while creating a windows forms
application. I noticed that when I quit the application or calling
Application.Exit, it hasn't really stop. Is there a quick way to say
"terminate all threads and quit"?

Set property isBackground to true.

Foreground and Background Threads
A foreground thread runs indefinitely, while a background thread
terminates once the last foreground thread has stopped. You can use
the IsBackground property to determine or change the background
status of a thread.
 
D

Dave

As someone else pointed out, make sure all your background threads are
marked as background. When the appdomain is exiting the runtime goes to
great lengths to unwind all threads and terminate. One thing to watch for
are threads that are blocked in unmanaged code - the runtime has no easy way
of forcing them to terminate.

Other then that there is no quick way to terminate all the threads.
 
A

Ahjay Muscha

As someone else pointed out, make sure all your background threads are
marked as background. When the appdomain is exiting the runtime goes to
great lengths to unwind all threads and terminate. One thing to watch for
are threads that are blocked in unmanaged code - the runtime has no easy way
of forcing them to terminate.

Ah yes, after some debugging I found out that there are references to
unmanaged code threads that are still running.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top