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
Post a Comment