进程正在等待完成

时间:2012-04-04 09:34:40

标签: c# process

我有一个应用程序,我正在启动多个进程。但看起来我在所有进程完成之前都没有捕获退出事件。 我怎么能这样做但不等待所有人完成?

这是我的代码:

foreach (var job in JobList.Where(x => x.Status == "Assigned"))
{
    var worker1 = new Process();

    worker1.StartInfo.UseShellExecute = false; 
    worker1.EnableRaisingEvents = true;
    worker1.StartInfo.CreateNoWindow = true;
    worker1.StartInfo.ErrorDialog = true;
    worker1.StartInfo.Arguments = job.BtcFilePath;
    worker1.StartInfo.FileName = job.ExeFilePath;
    worker1.Exited += new EventHandler(Worker1Exited);

    Processors.Add(worker1);

    Processors.Last().Start();
    Processors.Last().PriorityClass = ProcessPriorityClass.BelowNormal;

    job.Status = "Progressing";
    job.StartDate = worker1.StartTime;
    _jobRespository.Save(job);

    _state = State.CollectWorkerInformation;
}

...

void Worker1Exited(object sender, EventArgs e)
{
    Interlocked.Increment(ref _readyToDoFinalize);
}

BR

0 个答案:

没有答案