Wednesday, 15 August 2012

multithreading - C# and External Process Thread Behavor -



multithreading - C# and External Process Thread Behavor -

i have windows service wrapping quartz.net runs multiple long-running routines in parallel. of these routines launch casperjs externally scrape html. have situation appears every often, results 1 casperjs scrape consumed wrong thread. realized have no thought how process know thread "belongs" to, i'm assuming happen. thoughts appreciated. here code:

process casperprocess = new process(); casperprocess.outputdatareceived += new datareceivedeventhandler(processoutputhandler); casperprocess.errordatareceived += new datareceivedeventhandler(erroroutputhandler); processstartinfo info = new processstartinfo(casperbatchpath + " ", runparms.tostring()); info.useshellexecute = false; info.redirectstandardinput = true; info.redirectstandarderror = true; info.redirectstandardoutput = true; info.createnowindow = true; casperprocess.startinfo = info; casperprocess.start(); casperprocess.beginoutputreadline(); casperprocess.waitforexit(); casperprocess.close(); casperprocess.dispose();

found reply shortly after posting: class had static member, naturally threads writing on each other. d'oh!

c# multithreading casperjs

No comments:

Post a Comment