backgroundworker - C# - How to work with background worker with custom code -Run,Pause,Stop? -


i working background worker neither able synchronize progress bar nor able stop or abort process.

in dowork function

void bw_dowork(object sender, doworkeventargs e) {     if(bw.cancellationpending==true)     {         e.cancel=true;         return;     }     else     {         e.result = abc();     } } int abc() {     //my work     count++;     return count; }  void bw_runworkercompleted(object sender, runworkercompletedeventargs e) {     if(bw.cancellationpending==true)     {         button17.visibility = visibility.visible;         label1.content = "aborted";     }     button17.visibility = visibility.visible;     label1.content = "completed"; } private void cancel_click(object sender, routedeventargs e) {     if(bw.isbusy)     {         bw.cancelasync();     } } 

now want know how synchronize progress bar , how exit process?

have set backgroundworker.workerreportsprogress && backgroundworker.workersupportscancellation properties on instance true?

e.g.

var mybackgroundworker = new backgroundworker(); mybackgroundworker.workerreportsprogress = true; mybackgroundworker.workersupportscancellation = true; //the rest of init 

if want report progress, need call backgroundworker.reportprogress() method inside dowork.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -