c# - How to abort a thread started inside another function? -


monitor moni = new monitor(); thread t = new thread(() => moni.currusage(nics,200)); t.start(); 

i start thread named 't' inside 'form1_load' function. have added button. when click on button thread 't' should stop executing , create new thread these parameters.

monitor moni = new monitor(); thread t = new thread(() => moni.currusage(nics,950)); t.start(); 

i know in form_load event can use the

t.abort(); 

by making t member of form, can reference later on in button-click event handler.

graceful abort. although t.abort() gets job done, might left half-processed data in thread t. can catch threadabortexception in thread t gracefully end processing.

beware of overlap. second problem thread might not have aborted yet while new thread has started already. can prevent calling t.join() after calling t.abort().

hope helps.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -