Hello,
I'm having a problem trying to wrap my head around what I'm doing wrong while attempting a simple threading operation in one of my applications.
Here's what I'm after: I want the main thread to spawn a separate thread; that separate thread will open a program, feed that program an argument (a filename) and then once that program closes, the child thread will terminate and the main thread can continue it's work. I've created a very simple code example to illustrate. And truely, it doesn't even really HAVE to be a separate thread, it just needs to wait until the program is done with it's work. What am I doing wrong here? Any help would be most appreciated!
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Opening....");
var t = new Thread(StartProgram);
t.Start();
t.Join();
Console.WriteLine("Closed");
Console.ReadLine();
}
private static void StartProgram()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = @"c:\program.exe";
startInfo.Arguments = @"file.txt";
var p = Process.Start(startInfo);
p.WaitForExit();
}
}