Friday, 17 January 2014

C#: Execute Two Dependant Processes

Leave a Comment
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.

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
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 =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.