c# - Process Output Capture is VERY slow -


i'm running following code in order test if external application consuming 1 of dll's (updater code)

 processstartinfo psi = new processstartinfo()  {       filename = "tasklist.exe",       arguments = @"/m myservices.dll",       createnowindow = true,       redirectstandardoutput = true,       useshellexecute = false  };  process p = new process();  p.startinfo = psi;  p.start();  //debug output box, see returns  txtoutput.text = p.standardoutput.readtoend();  p.waitforexit();  refresh();   if (txtoutput.text.contains("testprogram.exe"))       messagebox.show("found it"); 

now, code works!!!....but stupid slow. can type same command cmd window , response in tenth of second, reason pause on line p.standardoutput.readtoend() taking anywhere 1 5 minutes!!

and actual question:

does know why slow? or possibly how fix , make acceptably fast?

update: more data

if use shell window , dont capture output, can watch task run in shell window. runs marginally (very marginally) faster, still sits , takes minute before output starts appearing in shell window. no idea doing.

streamreader.readtoend block until data read. try using process.outputdatareceived event.

process p = new process(); p.startinfo = psi; p.outputdatareceived += outputhandler; p.start();  p.beginoutputreadline();  p.waitforexit(); p.outputdatareceived -= outputhandler;  private void outputhandler(object sender, datareceivedeventargs outline) {     txtoutput.text += outline.data; } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -