CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    waiting for the process to die

    invoking winword process from the main thread , then wanna continue when the process has been closed (died)

    I not sure if i m setting all the parameters correctly or not.
    do u see anything obvious why while WINORD is still live it detects it not to be running?

    Cheers

    Code:
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                bProcessDone = 0;
                proc.StartInfo.FileName = "winword";
                proc.StartInfo.Arguments = pfile;
                proc.EnableRaisingEvents = false;
                proc.Start();
                Thread.Sleep(2000);
                bool bFound = false;
                for(;;)
                {
                    Process[] allProcs = Process.GetProcesses();
                    foreach (Process thisProc in allProcs)
                    {
                        if (proc.Id == thisProc.Id)
                        {
                            bFound=true;
                        }
                    }
    
                    if (bFound)
                    {
                        bFound = false;
                        continue;
                    }
                    else
                    {
                        break;
                    }
    
                }
    
    
    //  shoudl not be here if the process is still running but it is

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: waiting for the process to die

    you may just use Wait*****it() <-- that is W a i t F o r E x i t ( )

    Code:
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                bProcessDone = 0;
                proc.StartInfo.FileName = "winword";
                proc.StartInfo.Arguments = pfile;
                proc.EnableRaisingEvents = false;
                proc.Start();
    
                proc.Wait*****it();
                proc.Close();
                proc.Dispose();
    
    Last edited by Thread1; November 20th, 2008 at 10:07 PM. Reason: huh!?
    Busy

  3. #3
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: waiting for the process to die

    Thanks for the advice but I have laready tried that and it does not seem to work for me for some that i m determined to find out before i go home tonight or i wont be able to sleep

    Code:
               proc.StartInfo.FileName = "winword";
                proc.StartInfo.Arguments = pfile;
                proc.EnableRaisingEvents = false;
                proc.Start();
                Thread.Sleep(2000);
                proc.Wait*****it();
                proc.Close();
                proc.Dispose();
    
    // should not get here when winword is running but it is
    
                System.IO.FileInfo Info2 = new System.IO.FileInfo(pfile);

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: waiting for the process to die

    Try

    Code:
    proc.Start();
    proc.WaitForInputIdle( );
    proc.WaitF orE xit( );

  5. #5
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: waiting for the process to die

    Thanks that worked Arjay

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured