积极答复者
Main()方法里使用Process问题

问题
-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.ComponentModel; using System.IO; namespace testMain1 { class Program { static void Main(string[] args) { string path = Directory.GetCurrentDirectory(); Process pro = new Process(); pro.StartInfo.FileName = path + "\\testMain1.exe"; pro.StartInfo.Arguments = "girl good!"; pro.StartInfo.UseShellExecute = false; pro.Start(); switch (args[0]) { case "boy": Console.WriteLine("hello boy!"); break; case "girl": Console.WriteLine("hello girl!"); break; default: Console.WriteLine("hi, man!"); break; } Console.WriteLine("args[1] value is :" + args[1]); Console.ReadLine(); } } }
会进入无限循环状态,能详细解释下为什么嘛?本人理解不透彻,有点模糊,请指教~
答案
-
您好,
那應該將那段代碼分到2支程式之中,如下,//ConsoleApplication1 static void Main(string[] args) { switch (args[0]) { case "boy": Console.WriteLine("hello boy!"); break; case "girl": Console.WriteLine("hello girl!"); break; default: Console.WriteLine("hi, man!"); break; } Console.WriteLine("args[1] value is :" + args[1]); Console.ReadLine(); } //ConsoleApplication2 為了方便,可將 ConsoleApplication1 專案加入參考,這樣 建置專案時,會一併將 ConsoleApplication1.EXE 輸出 static void Main(string[] args) { string path = Directory.GetCurrentDirectory(); Process pro = new Process(); pro.StartInfo.FileName = path + "\\ConsoleApplication1.exe"; pro.StartInfo.Arguments = "girl good!"; pro.StartInfo.UseShellExecute = false; pro.Start(); }
- 已标记为答案 xiechunxiang 2013年9月12日 8:20
全部回复
-
您好,
那應該將那段代碼分到2支程式之中,如下,//ConsoleApplication1 static void Main(string[] args) { switch (args[0]) { case "boy": Console.WriteLine("hello boy!"); break; case "girl": Console.WriteLine("hello girl!"); break; default: Console.WriteLine("hi, man!"); break; } Console.WriteLine("args[1] value is :" + args[1]); Console.ReadLine(); } //ConsoleApplication2 為了方便,可將 ConsoleApplication1 專案加入參考,這樣 建置專案時,會一併將 ConsoleApplication1.EXE 輸出 static void Main(string[] args) { string path = Directory.GetCurrentDirectory(); Process pro = new Process(); pro.StartInfo.FileName = path + "\\ConsoleApplication1.exe"; pro.StartInfo.Arguments = "girl good!"; pro.StartInfo.UseShellExecute = false; pro.Start(); }
- 已标记为答案 xiechunxiang 2013年9月12日 8:20