1、 c#如何用process调用exe文件(含参数)??参见我的经验如下,如何开启多线程请参加我的经验如下
2、 testCallExe文件中Program.cs文件,添加代码如下所示namespace testCallExe{class Program{private static string[] ss = new string[10];static void Main(string[] args){ss[0] = "jingyan.baidu.com/article/90808022090decfd91c80f8e.html";ThreadStart threadStart = new ThreadStart(startThread);var thread = new Thread(threadStart);thread.Start();//开始线程}private static void startThread(){Console.WriteLine("---------开始了新线程---------");string cPath = ".\\..\\..\\..\\WebBrowserExe\\bin\\Debug\\";string cParams = ss[0];string filename = Path.Combine(cPath, "WebBrowserExe.exe");var proc = new Process{StartInfo = new ProcessStartInfo{FileName = filename,Arguments = cParams,UseShellExecute = false,RedirectStandardOutput = true,CreateNoWindow = true}};proc.Start();while (!proc.StandardOutput.EndOfStream){string line = proc.StandardOutput.ReadLine();// do something with lineConsole.WriteLine(line);}Thread.Sleep(4000);Console.WriteLine("---------关闭exe---------");//proc.CloseMainWindow();//proc.Close();//proc.WaitForExit();Console.WriteLine("---------线程结束---------");Console.ReadLine();}}}}
3、 WebBrowsweExe中的Program.cs添加代码如下:namespace WebBrowserExe{class Program{static void Main(string[] args){if( args.Length <= 0){Application.Exit();}string href = args[0];Thread.Sleep(2000);Console.WriteLine(href + " 输出传入的参数");Console.ReadLine();}}}
4、 WebBrowsweExe生成exe,如下图所示
5、 运行程序如下所示:从exe中获取到的输出值已经在控制台中打印出来了
6、 程序结束如下:图中显示的是线程已经结束。
7、如果您觉得有用,记得在下方点击投票、点赞、关注、留言,小编会定期奉上更多的惊喜哦,您的支持才是小编继续努力的动力,么么哒。