c# - Start Process and wait for Exit code without freezing -


i'm trying port program on had once made in nsis c# winforms, , having issue when call process, adb.exe, whole program locks throws me final output after few seconds.

i realise may have been asked number of times, still can't find solution myself after lot of googling (plus i'm new @ using winforms). below code:

public static int runadb(string args, out string output) {     badbrunning = true;      adbproc.startinfo.arguments = args;     adbproc.exited += new eventhandler(adbexithandler);     adbproc.start();      // read output string output     output = adbproc.standardoutput.readtoend();      while (badbrunning)     {         system.threading.thread.sleep(100);     }      return adbproc.exitcode; }  private static void adbexithandler(object sender, eventargs args) {     badbrunning = false; } 

and code calls it:

public static void baseoperations(label outputwindow, progressbar operationsbar, int opindex) {     // run server     if (opindex == 0)     {         outputline(outputwindow, "shutting down existing adb server");         runadb("kill-server", out outtext);         operationsbar.value += 1; // 1%          outputline(outputwindow, "restarting adb server...");         runadb("start-server", out outtext);         operationsbar.value += 1; // 2%;     } } 

you need subscribe process exited event achieve this.

try this:

public static int runadb(string args, out string output) {     adbproc.startinfo.arguments = args;     adbproc.exited += new eventhandler(processexithandler);     adbproc.start();      // read output string output     output = adbproc.standardoutput.readtoend();         }  private void processexithandler(object sender,eventargs args) {  //your process exited , whatever want.  } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -