Click to See Complete Forum and Search --> : waiting for the process to die


Saeed
November 20th, 2008, 08:05 PM
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



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

Thread1
November 20th, 2008, 09:05 PM
you may just use Wait*****it() <-- that is W a i t F o r E x i t ( )


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();

Saeed
November 20th, 2008, 10:16 PM
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 ;)


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

Arjay
November 21st, 2008, 01:10 AM
Try

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

Saeed
November 23rd, 2008, 09:06 PM
Thanks that worked Arjay