A
Alan T
I want to make sure my process is completed:
Process.Start();
bool finished = false;
while (!finsihed)
{
Thread.Sleep(1000);
if (Process.HasExited)
{
Thread.Sleep(1000);
finsihed = true;
}
}
Are these correct ?
The reason I inserted Thread.Sleep(1000) before exiting the loop is my
prcess is creating a text file and exporting data to this text file, so I
need to give time for the process to close the text file even it it
finished.
However, I have to run the above code 100 times (ie. to create 100 text
files and export data to 100 text files, I will open the text file after the
above code is executed each time for each text file), sometime I still got
the exception when I tried to open the textfile in my code:
The text file is being used by other process.
So it seems the process has not finished when I tried to open the text file
at run time.
Process.Start();
bool finished = false;
while (!finsihed)
{
Thread.Sleep(1000);
if (Process.HasExited)
{
Thread.Sleep(1000);
finsihed = true;
}
}
Are these correct ?
The reason I inserted Thread.Sleep(1000) before exiting the loop is my
prcess is creating a text file and exporting data to this text file, so I
need to give time for the process to close the text file even it it
finished.
However, I have to run the above code 100 times (ie. to create 100 text
files and export data to 100 text files, I will open the text file after the
above code is executed each time for each text file), sometime I still got
the exception when I tried to open the textfile in my code:
The text file is being used by other process.
So it seems the process has not finished when I tried to open the text file
at run time.