2012-07-04 62 views
0

我嘗試從c#執行PowerShell腳本而無需等待結果。無需等待結果就執行PowerShell腳本

string cmdArg = "MyScript.ps1"; 
//Create New Runspace 
Runspace runspace = RunspaceFactory.CreateRunspace(); 
runspace.ApartmentState = System.Threading.ApartmentState.STA; 
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread; 
runspace.Open(); 

//Adds the command 
pipeline.Commands.AddScript(cmdArg); 
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); 

//Do not wait for a result 
pipeline.InvokeAsync(); 
runspace.Close(); 

但它一直等到劇本結束!

回答