我有一个要求,我需要生成多个线程来执行一个进程。这里的过程是一个exe。当多个线程尝试访问共享路径中的exe时,我遇到了问题。 我尝试使用锁。即使没有帮助。任何帮助表示赞赏。请在下面找到代码。
Task t;
t = Task.Factory.StartNew(() =>
{
//lock (thisLock)
//{
// process = ProcessHelper.StartNew(objPSI.FileName, objPSI.Arguments, true, 5000);
// process.BeginOutputReadLine();
// process.OutputDataReceived += process_OutputDataReceived;
//}
process = ProcessHelper.StartNew(objPSI);
process.BeginOutputReadLine();
process.OutputDataReceived += process_OutputDataReceived;
//}
//var token = Task.Factory.CancellationToken;
//Task.Factory.StartNew(() =>
//{
// //this.label1.Text = "Task past first work section...";
//}, token, TaskCreationOptions.None, context);
}
)
.ContinueWith(_ =>
{
if (process.ExitCode != 0)
{
ErrorTexts.Add(process.StandardOutput.ReadToEnd());
}
else
{
ProgressText = "::: Migration Successful";
}
process.Close();
});