3

I have a application which will open a two microsoft ppsx file one after another. for that i have used process object to run the files. mention bellow

Process process = Process.Start(@"E:\test\test.ppsx");

I need to run the files in such a way that after finishing the first file ,second file should run automatically. can some one suggest me how can achieve that.

Arup
  • 55
  • 3
  • 6
  • You can try using Process.WaitForExit() http://stackoverflow.com/questions/6390030/c-sharp-making-a-process-start-wait-until-the-process-has-start-up – Murkaeus May 02 '13 at 07:35
  • Are you telling that after opening the first file you want to open another ? Not after closing the first file opening other – Guru Kara May 02 '13 at 07:37

4 Answers4

4

You can use WaitForExit method to wait to end process (Something like this):

var process1 = Process.Start(...);
process1.WaitForExit();

var process2 = Process.Start(...);

or subscribe into a Process.Exited event and execute another process after the first one. Check this for your reference.

roybalderama
  • 1,650
  • 21
  • 38
  • This is working fine. but I need when the second process will start first process should stop or close. is it possible? – Arup May 02 '13 at 08:08
  • I have two files. I want to run that two files consecutively one after another, according to your suggestion it is running. but I want to stop the first process to start the second one. – Arup May 02 '13 at 08:15
  • yes, that I want to know the time taken by the first process. and after that time the second one will open – Arup May 02 '13 at 08:44
1

You can use Process.WaitForExit method.

Instructs the Process component to wait indefinitely for the associated process to exit.

Also check Process.Exited event.

Occurs when a process exits.

Process process = Process.Start(@"E:\test\test.ppsx");
process.WaitForExit();
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
1

Use Process.WaitForExit()

class Program
{
    static void Main(string[] args)
    {
        Task.Run(() =>
        {
            Process.Start(@"c:\temp\presentation1.pptx").WaitForExit();
        }).ContinueWith(o => 
        {
            Process.Start(@"c:\temp\presentation2.pptx").WaitForExit();
        });
        Console.ReadKey();
    }       
}
StaWho
  • 2,488
  • 17
  • 24
0

You should get all the ppsx files from the test directory in the E drive in an array and process on the array of ppsx files according to your requirements.

 string[] files = Directory.GetFiles("your path");

loop through the array and pass each file path to the Process constructor and as lexeRoy said you can WaitForExit.

Jibran Khan
  • 3,236
  • 4
  • 37
  • 50