How to kill Thread on exit?

If you want the app to exit when the main thread has finished, you can just make the new thread a background thread:

Thread t = new Thread(Main.MyThread);
t.IsBackground = true;
t.Start();

Basically the process will exit when all the foreground threads have exited.

Note that this could be bad news if the background thread is writing a file when the form is closed, or something similar…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)