我在C#中順序啓動多個進程時遇到了一些問題。我試着開始的這些過程只需花費30秒就可以完成他的程序。我不希望這些進程竊取任何應用程序的焦點。我已經試過兩種方法(以下代碼到一個循環語句):如何避免進程從C#應用程序竊取焦點?
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "References\\InclinacaoHGrid.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.Arguments = i.ToString() + " " + j.ToString() + " " +
valA + " " + valS + " " + valP + " " + pathNodes;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Start();
myProcess.WaitForExit();
而且使用Interaction.Shell與參數「AppWinStyle.MinimizedNoFocus」:
int pid = Interaction.Shell("References\\InclinacaoHGrid.exe " + i.ToString() + " " + j.ToString() + " " +
valA + " " + valS + " " + valP + " " + pathNodes, AppWinStyle.NormalNoFocus,true);
這兩種方法沒」因爲流程(或流程的開始和結束的行爲)正在從任何應用程序中竊取焦點,所以對我很有幫助。當我的應用程序運行時,我無法做任何事情。
[開始一個進程而沒有竊取焦點(C#)]的可能的重複(http://stackoverflow.com/questions/2121911/starting-a-process-without-stealing-focus-c) –