C#: Execute Two Dependant Processes
This example shows how to run 2 program in application and the second program need to run after the first program successfully start. The example will use 2 program which is Notepad and Paint. The Notepad need to run first and after Notepad successfully run, the Paint application will start to open program. Let see the code.
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Two Dependant Processes
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace TwoDependantProcesses
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press Enter to start Notepad (i.e. Process 1)");
Console.ReadKey();
Console.WriteLine("Starting Notepad...");
Thread t1 = new Thread(new ThreadStart(StartProcess1));
t1.Start();
while (t1.IsAlive == true)
{
System.Threading.Thread.Sleep(1000);
}
Console.WriteLine("Notepad Stopped. Starting MSPaint (i.e. Process 2)");
StartProcess2();
Console.WriteLine("MSPaint Stopped. Press Enter to Exit");
Console.ReadKey();
}
static void StartProcess1()
{
Process proc = new Process();
proc.StartInfo.FileName = "Notepad.exe";
proc.Start();
Console.WriteLine("Notepad running...");
proc.WaitForExit();
}
static void StartProcess2()
{
Process proc = new Process();
proc.StartInfo.FileName = "MSPaint.exe";
proc.Start();
Console.WriteLine("MSPaint running...");
proc.WaitForExit();
}
}
}
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)