C#中启动进程的三种办法

来源:这里教程网 时间:2026-02-21 13:06:47 作者:

    启动子进程,不等待子进程结束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.启动子进程,等待子进程结束,并获得输出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.使用默认的浏览器打开urlview plaincopy to clipboardprint?
    ·········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);   
    }   

    以上就是C#中启动进程的三种办法的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关推荐