C# 如何在.net中完成三个过程后执行方法

C# 如何在.net中完成三个过程后执行方法,c#,.net,process,C#,.net,Process,我使用Process.start并通过传递不同的参数来运行三个相同的进程。我需要一个逻辑,就像只有在这些进程完成后,我才能执行最后两个名为fourthmethod()的方法;sendmail()。如何做到这一点。现有的逻辑一直在抛出这两个方法,但我只需要在完成三个过程后,即三个方法firstmethod(),secondmethod(),第三种方法() 此代码显示触发三个不同的进程 // three same test.exe process for(int i=0;i<3;i+

我使用Process.start并通过传递不同的参数来运行三个相同的进程。我需要一个逻辑,就像只有在这些进程完成后,我才能执行最后两个名为
fourthmethod()的方法;sendmail()。如何做到这一点。现有的逻辑一直在抛出这两个方法,但我只需要在完成三个过程后,即三个方法
firstmethod()
secondmethod()
第三种方法()
此代码显示触发三个不同的进程

 // three same test.exe process
    for(int i=0;i<3;i++)
    {
    Process.Start("test.exe",i);
    }
一种方法是:)

更新代码:

使用系统;
使用系统诊断;
班级计划
{
静态整数计数=0;
静态对象obj=新对象();
静态void Main(字符串[]参数)
{
流程[]流程=新流程[3];
对于(int i=0;i<3;i++)
{
进程[i]=Process.Start(“notepad.exe”);
进程[i]。EnableRaisingEvents=true;
进程[i]。退出+=程序退出;
}
Console.ReadLine();
}
已退出私有静态无效程序(对象发送方,System.EventArgs e)
{
锁(obj)
{
计数++;
}
如果(计数=3)
控制台。写入线(“已完成”);
}
}

使用OnExit事件。见以下网页:
Main(strin[] args)
{
if(args[0]==0)
{
firstmethod();
}
if(args[0]==1)
{
secondmethod();
}
if(args[0]==2)
{
thirdmethod();
}
fourthmethod();
sendmail();
}
 // three same test.exe process
    for(int i=0;i<4;i++)   // the two method should execute only after 3 processes
    {
    Process.Start("test.exe",i);
    }
Main(strin[] args)
{
if(args[0]==0)
{
firstmethod();
}
if(args[0]==1)
{
secondmethod();
}
if(args[0]==2)
{
thirdmethod();
}
if(args[0]==3)    // i shall increment to 3 only if the first three processes are ran 
{ 
fourthmethod();
sendmail();
 } 
}
using System;
using System.Diagnostics;

class Program
{
  static int count = 0;
  static object obj = new object();
  static void Main(string[] args)
  {
    Process[] Processes = new Process[3];
    for (int i = 0; i < 3; i++)
    {
        Processes[i] = Process.Start("notepad.exe");
        Processes[i].EnableRaisingEvents = true;
        Processes[i].Exited += Program_Exited;
    }
    Console.ReadLine();
  }

  private static void Program_Exited(object sender, System.EventArgs e)
  {
    lock (obj)
    {
        count++;
    }
    if (count == 3)
        Console.WriteLine("Finised");
  }
}