0

I have two exe(two console apps) named first.exe and second.exe, in which first is invoking second exe three times by using Process.start() and passing different arguments.After these three execution finishes i want to run a method(only after finishing three methods).How to do that. This is the way i am handling the three invokes in second.exe

 static void Main(string[] args)
        {


            if (args[0] == "TC" && args[1] == "CS")
            {
                Processfiles("TCS");
            }
            if (args[0] == "RC" && args[1] == "CS")
            {
                Zipfiles("RCS");
            }
            if (args[0] == "CC" && args[1] == "CS")
            {
                Leveragefiles("CTS");
            }

            Downloadfiles();
}

Here my question is how to execute Downloadfiles(); method after the completion of three methods Processfiles("TCS");,Zipfiles("RCS");,Leveragefiles("CTS");. Here the completion time of three methods vary at different times

Code used to start second.exe is

   ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = System.Configuration.ConfigurationManager.AppSettings["PathExe"];
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dtr in ds.Tables["testG"].Rows)
                {
                    startInfo.Arguments = dtr["TC_CODE"].ToString() + " " + dtr["CC_CODE"].ToString();
                    Process.Start(startInfo);
                    // System.Diagnostics.Process.Start(System.Configuration.ConfigurationManager.AppSettings["PathExe"], dtr["VENDOR_CODE"].ToString() + " " + dtr["TECH_CODE"].ToString());
                }
            }
        }
        catch (Exception ex)
        {
            mail.SendMail2(System.Configuration.ConfigurationManager.AppSettings["EmailFrom"], System.Configuration.ConfigurationManager.AppSettings["EmailCc"], null, ex.Message, "error", true);
            log.Error(ex.Message);
        }
peter
  • 8,158
  • 21
  • 66
  • 119

1 Answers1

1

you can use threading task for this. Use the conditional operator on the task as it is

using System.Threading.Tasks;
...

Task.Factory.StartNew(() => Processfiles("TCS"));
Task.Factory.StartNew(() => Zipfiles("RCS"));
Task.Factory.StartNew(() => Leveragefiles("CTS"));
Task.WaitAll();//to make sure all the task is complete
 Downloadfiles();
Sudipto Sarkar
  • 346
  • 2
  • 11