Three ways to start a process in C #

Source: Internet
Author: User
  1. Start a 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 child process 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.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)
    {
    String output = Myoutput.readtoend ();
    This.processResults.Text = output;
    }
    }
    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)
    {
    String output = Myoutput.readtoend ();
    This.processResults.Text = output;
    }
    }


    3. Open Urlview plaincopy to clipboardprint using the default browser?
    ········· 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 is the content of three ways to start a process in C #, more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.