Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waiting until an external process has been completed

I have a method that is called, although I would like the message box to be shown after the method has been completed (right now the message box is shown straight after the method is called):

if (Check == true)
{
    StartConvIpod();
}
else
{

}
MessageBox.Show("Operation Successful!");

StartConvIpod:

      private void StartConvIpod()
        {

            string res = Directory.EnumerateFiles("dump").
    OrderBy(x => File.GetCreationTime(x)).Last();

            string sub = res.Substring(5);

            string sub2 = sub.Substring(0, sub.Length - 4);


            Process p = new Process();
            p.StartInfo.WorkingDirectory = "dump";
            p.StartInfo.FileName = "ffmpeg.exe";
            p.StartInfo.Arguments = "-i " + sub + " -f mp4 -vcodec mpeg4 -b 700k -aspect 4:3 -r 23.98 -s 320x240 -acodec ac3 -ar 48000 iPodConversions\\" + sub2 + ".mp4";
            p.Start();
}
like image 204
Adam Jones Avatar asked Jul 21 '11 16:07

Adam Jones


1 Answers

You'll want to add this:

p.Start();
p.WaitForExit(); // or p.WaitForExit(Timeout-Period-In-Milliseconds);
like image 60
Jason Down Avatar answered Oct 18 '22 05:10

Jason Down