我會遇到從多線程WinForm應用程序執行單個PowerShell腳本的任何問題嗎?我主要關心的是鎖定PowerShell腳本的WinForm線程。多線程WinForm調用PowerShell腳本.Net 3.5
for (int i = 0; i <= toProcess; i++)
{
bWorker.ReportProgress(0, i.ToString());
PowerShellProcs workPs = new PowerShellProcs();
workPs.CusId = CustomerDataTable.Rows[i]["CustomerID"].ToString();
ThreadStart threadDelegate = new ThreadStart(workPs.DoPs);
Thread newThread = new Thread(threadDelegate);
newThread.Name = CustomerDataTable.Rows[i]["CustomerID"].ToString();
newThread.Start();
if (toProcess == i)
{
resetEvent.Set();
}
Thread.Sleep(1000);
//threads.Add(newThread);
}
class PowerShellProcs
{
public string CusId;
public void DoPs()
{
String customerId = CusId;
var scriptfile = @"c:\ProcessCustomer.ps1";
Process _Proc = new Process();
_Proc.StartInfo = "Powershell.exe";
_Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_Proc.StartInfo.Arguments = "'" + customerId + "' ";
_Proc.Start();
}
}
爲什麼你想在另一個線程上啓動一個進程? '_Proc.Start()'不會被阻止 –
嘗試同時運行X更新。我過於複雜嗎? – eHaze