C#启动进程的几种常用方法
作者:欧阳不疯 时间:2023-06-18 04:13:48
本文实例讲述了C#启动进程的几种常用方法。分享给大家供大家参考。具体如下:
1.启动子进程,不等待子进程结束
private void simpleRun_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}
2.启动子进程,等待子进程结束,并获得输出
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.使用默认的浏览器打开URL
private void launchURL_Click(object sender, System.EventArgs e)
{
string targetURL = @https://www.aspxhome.com;
System.Diagnostics.Process.Start(targetURL);
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,进程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mybatis-plus 扩展批量新增的实现
2023-07-14 14:24:13
Java Eclipse进行断点调试的方法
2023-06-14 06:31:27
![](https://img.aspxhome.com/file/2023/9/71869_0s.png)
C++ vector的简单实现
2023-04-09 17:13:02
基于Android6.0实现弹出Window提示框
2023-01-12 05:23:25
![](https://img.aspxhome.com/file/2023/5/106035_0s.jpg)
Android开发手册TextView属性实现效果盘点
2022-03-10 09:29:53
![](https://img.aspxhome.com/file/2023/2/109192_0s.jpg)
完美解决Spring Boot前端的Access-Control-Allow-Origin跨域问题
2023-09-19 10:16:28
springBoot整合redis使用案例详解
2022-07-02 10:51:33
![](https://img.aspxhome.com/file/2023/9/75659_0s.png)
使用MyBatisPlus自动生成代码后tomcat运行报错的问题及解决方法
2022-02-23 05:24:55
![](https://img.aspxhome.com/file/2023/5/129235_0s.png)
Kotlin LinearLayout与RelativeLayout布局使用详解
2021-12-06 02:07:30
![](https://img.aspxhome.com/file/2023/8/137998_0s.png)
Android自定义view系列之99.99%实现QQ侧滑删除效果实例代码详解
2022-05-08 15:35:55
![](https://img.aspxhome.com/file/2023/3/100593_0s.png)
解析从源码分析常见的基于Array的数据结构动态扩容机制的详解
2021-07-19 09:01:03
Spring Security中的Servlet过滤器体系代码分析
2023-03-23 19:05:34
![](https://img.aspxhome.com/file/2023/3/92553_0s.png)
解析C#设计模式编程中外观模式Facade Pattern的应用
2021-08-08 05:10:37
![](https://img.aspxhome.com/file/2023/9/67549_0s.jpg)
springboot实现多模块项目添加一新模块
2021-09-22 16:43:09
![](https://img.aspxhome.com/file/2023/7/77377_0s.jpg)
Java注解Annotation原理及自定义注解代码实例
2023-04-30 10:18:09
Android打开GPS导航并获取位置信息返回null解决方案
2021-08-31 09:21:19
springboot调用支付宝第三方接口(沙箱环境)
2023-11-25 06:12:08
![](https://img.aspxhome.com/file/2023/8/58748_0s.png)
java用户管理注册功能 含前后台代码
2022-08-01 12:05:11
![](https://img.aspxhome.com/file/2023/1/132071_0s.jpg)
Java泛型中<?>和<T>的区别浅析
2023-11-25 05:20:09
Java一维数组和二维数组元素默认初始化值的判断方式
2022-03-08 21:17:49
![](https://img.aspxhome.com/file/2023/4/125234_0s.png)