I am executing a thread which invokes BCP out in command prompt using C# win apps.
I want to do some action if thread execution is completed i.e. BCP out is completed.
BCP out is carried on local machine.
How should i check whether the thread execution is completed or not ???
my code looks like
using(this.proc = new Process())
{
var procStartInfo =
new ProcessStartInfo(cmdFileName)
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true
};
this.proc.StartInfo = procStartInfo;
if(this.proc.Start())
{
var thread1 = new Thread(this.GetError) { IsBackground = true };
var thread2 = new Thread(this.GetOutput) { IsBackground = true };
thread1.Start();
thread2.Start();
// check if thread execution is completed then do some logic
}
}
A standard trick is:
Update
Okay so you actually want to check if the process has exited?
Then you have the HasExited property of
System.Diagnostics.Process.Here’s a slightly dirty way: