1. Start an independent process and use the following namespace: using system. diagnostics; process class: process; process-related parameter Information Class: processstartinfo
2. Console app code waiting for startup:
Using system;
Using system. Threading;
Namespace showconsoleapp
{
Class Program
{
Static void main (string [] ARGs)
{
Console. writeline ("app start! ");
Foreach (string item in ARGs)
{
Console. writeline ("accept a Arg that is {0}", item );
Thread. Sleep (3000 );
}
Console. writeline ("app stop! ");
}
}
}
3. Startup Mode: parallel and serial modes. Compare the differences between codes.
Using system;
Using system. Threading;
Using system. diagnostics;
Namespace hdtest
{
Class Program
{
Static void main (string [] ARGs)
{
For (INT I = 0; I <2; I ++)
{
// Parallel execution: Multiple same-life instance processes are executed together.
Runmutilinstanceprocess (I );
// Serial. After a process is started, run the next
// Waitsonprocess (I );
Thread. Sleep (2000 );
}
Console. Readline ();
}
Static void runmutilinstanceprocess (int I)
{
String apppath = @ "E: \ vs2010code \ apptest \ showconsoleapp \ bin \ debug \ showconsoleapp.exe ";
Processstartinfo process = new processstartinfo ();
Process. filename = apppath;
Process. Arguments = "process" + I. tostring ();
Process. useshellexecute = false;
Process. createnowindow = true;
Process. redirectstandardoutput = true;
Process. Start (process );
// String result = P. standardoutput. readtoend ();
// Console. writeline ("the console app output is {0}", result );
Console. writeline ("process {0} start", I );
}
Static void waitsonprocess (int I)
{
Process = new process ();
String apppath = @ "E: \ vs2010code \ apptest \ showconsoleapp \ bin \ debug \ showconsoleapp.exe ";
Process. startinfo. filename = apppath;
Process. startinfo. Arguments = "process" + I. tostring ();
Process. startinfo. useshellexecute = false;
Process. startinfo. createnowindow = true;
Process. startinfo. redirectstandardoutput = true;
// Process. startinfo. windowstyle = processwindowstyle. normal;
// Start the process
Process. Start ();
Console. writeline ("process {0} start", I );
// Wait that the process exits
Process. waitforexit ();
Console. writeline ("the process had exits ");
// Now read the output of the DOS Application
String result = process. standardoutput. readtoend ();
Console. writeline ("the console app output is {0}", result );
}
}
}