c# - Why background thread not exiting when form closes? -


as understand it, if set _mythread.isbackground = true thread should exit when form closed. unfortunately i'm not finding thread exiting. here code looks like:

private void mainform_load(object sender, eventargs e) {     // <snip>     daemon = new daemon();     // <snip> }  public daemon() {     // start main thread of connection checking , work     _mainthread = new thread(() => mainthread(this));     _mainthread.isbackground = true;     _mainthread.start(); }  /// <summary> /// work main thread does. /// </summary> private void mainthread(daemon daemon) {     while(true)     {         try         {             // things.             thread.sleep(2000);            // sleep bit not hammer.         }         catch (exception e)         {             logger.exception(e);         }     } } 

i thought since thread started form setting isbackground=true force close on form exit.

am missing or misinterpreting something?

according documentation background thread wont prevent process terminating. there no guarantee thread finish "nicely", whatever may mean.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -