Home  >  Article  >  Backend Development  >  Three ways to start a process in C#

Three ways to start a process in C#

黄舟
黄舟Original
2016-12-21 14:42:431700browse
  1. Start the child process without waiting for the child process to end view plaincopy to clipboardPRint?
    ··········10·········20·······30···· ····40········50········60········70·········80········90 ········100········110·······120·······130········140·······150
    private void simpleRun_Click(object sender, System.EventArgs e)
    { System.Diagnostics.Process.Start(@"C:listfiles.bat");
    }
    private void simpleRun_Click(object sender, System.EventArgs e)
    { System .Diagnostics.Process.Start(@"C:listfiles.bat");
    }


    2. Start the subprocess, wait for the subprocess to end, and get the output view plaincopy to clipboardprint?
    private void runSyncAndGetResults_Click(object sender, System .EventArgs e)
    {
    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:listfiles.bat");
    psi.RedirectStandardOutput = true;
    psi.WindowStyle = System.Diagnostics.ProcessWindowSt yle.Hidden ;
    psi.UseShellExecute = false;
    System.Diagnostics.Process listFiles;
    listFiles = System.Diagnostics.Process.Start(psi);
    System.IO.StreamReader myOutput = listFiles.StandardOutput;
    ListFiles.WaitForExit(2000);
                                                                                                       
    }
    private void runSyncAndGetResults_Click(object sender, System.EventArgs e)
    {
    System .Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:listfiles.bat");
    psi.RedirectStandardOutput = true;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    psi.UseShellExecute = false;
    System.Diagnostics.Process listFiles;
    listFiles = System.Diagnostics.Process.Start(psi);
    System.IO.StreamReader myOutput = listFiles.StandardOutput;
    listFiles.WaitForExit(2000);

    if (listFiles.HasExited) R {
    string output = myoutput.readtoend ();
    this.processResults.text = output;
    } }3. rint?
    ... ·10········20········30········40········50·········60·· ·····70········80········90········100········110········120· ······130·······140······150
    private void launchURL_Click(object sender, System.EventArgs e)
    {
    string targetURL = @http://www.duncanmackenzie .net;
    System.Diagnostics.Process.Start(targetURL);
    }




    The above are the contents of the three ways to start the process in C#. For more related content, please pay attention to the PHP Chinese website (www.php.cn )!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn