c# - thread suicide question -
i want kill thread when bad happen. what's suggestion thread suicide?
you should never "kill" thread. main program, can abort using thread.abort method, not recommended, , unnecessary.
your thread should nothing more method executing long loop. if "really bad" happens, return method , thread end.
this enough such loop:
private void mythreadloop() { try { while (somecondition) { // lengthy operation } } catch (exception ex) { log.error("something bad happened: ", ex); } } public void start() { thread t = new thread(mythreadloop); t.start() }
on other hand, if need main program kill thread (but not "suicide" named it), should signal thread want end, , not abort without knowing going on in background.
Comments
Post a Comment