c# - BackgroundWorker not working with TeamCity NUnit runner -
i'm using nunit test view models in wpf 3.5 application , i'm using backgroundworker
class execute asynchronous commands.the unit test running fine nunit runner or resharper runner fail on teamcity 5.1 server.
how implemented :
i'm using viewmodel
property named isbusy
, set false on backgroundworker.runworkercompleted
event. in test i'm using method wait backgroundworker finish :
protected void waitforbackgroundoperation(viewmodel viewmodel) { console.writeline("waitforbackgroundoperation 1"); int count = 0; while (viewmodel.isbusy) { console.writeline("waitforbackgroundoperation 2"); runbackgroundworker(); console.writeline("waitforbackgroundoperation 3"); if (count++ >= 100) { assert.fail("background operation long"); } thread.sleep(1000); console.writeline("waitforbackgroundoperation 4"); } } private static void runbackgroundworker() { dispatcher.currentdispatcher.invoke(dispatcherpriority.background, new threadstart(delegate { })); system.windows.forms.application.doevents(); }
well, works , hangs build. suppose it's application.doevents()
don't know why...
edit: added traces (see code above) , in log have :
waitforbackgroundoperation 1 waitforbackgroundoperation 2 waitforbackgroundoperation 2 waitforbackgroundoperation 2 ...
how possible ?!
you launching bunch of background tasks, 1 per second. move runbackgroundworker above loop.
protected void waitforbackgroundoperation(viewmodel viewmodel) { console.writeline("waitforbackgroundoperation 1"); runbackgroundworker(); thread.sleep(100); // wait thread set isbusy, may not needed int count = 0; while (viewmodel.isbusy) { console.writeline("waitforbackgroundoperation 2"); if (count++ >= 100) { assert.fail("background operation long"); } thread.sleep(1000); console.writeline("waitforbackgroundoperation 3"); } } private static void runbackgroundworker() { dispatcher.currentdispatcher.invoke(dispatcherpriority.background, new threadstart(delegate { })); }
the doevents should not needed.
Comments
Post a Comment