winforms - System.ComponentModel.BackgroundWorker never invokes ProgressChanged -


i rewrote windows forms application use backgroundworker instances instead of using manually created "worker threads". after checkin noticed tests started fail. after debugging can demonstate problems showing following 2 tests:

    [test]             public void test_a()     {          bool progresschanged = false;         var worker = new backgroundworker();         worker.workerreportsprogress = true;         worker.dowork += (s, e) => worker.reportprogress(0, null);         worker.progresschanged += (s, e) => progresschanged = true;         worker.runworkerasync();         thread.sleep(100);         progresschanged.shouldbetrue();                 }      [test]             public void test_b()     {          //creation of o form component causes (?) test fail, dispose         var view = new form();         view.dispose();          bool progresschanged = false;         var worker = new backgroundworker();         worker.workerreportsprogress = true;         worker.dowork += (s, e) => worker.reportprogress(0, null);         worker.progresschanged += (s, e) => progresschanged = true;         worker.runworkerasync();         thread.sleep(100);         progresschanged.shouldbetrue();                 } 

test_a success while test_b fails. regardless if sleep 100 ms or 100 minutes. why?? production code seem work though, annoying not being able have regression test suite works (i have other test creating forms components , these tests must executed before test using backgroundworker) next step examine source code of backgroundworker, before thought i`d check here.

regards michael

add

windowsformssynchronizationcontext.autoinstall = false; 

in test_b() before else. backgroundworker, wich ui (ie: winforms) oriented, wild guessing how sync things, not want. have here explanation (especially scott berry): windowsformssynchronizationcontext


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -