[C#]Process.Exited事件觸發的執行緒會受Process.SynchronizingObject屬性設定的影響
namespace WindowsFormsApplication13 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e)
{
var process = Process.Start("calc.exe");
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(process_Exited);
textBox1.Text = "Main Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString();
Console.Read();
}
void process_Exited(object sender, EventArgs e)
{
MessageBox.Show("Process Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString());
}
}
}
namespace WindowsFormsApplication13 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e)
{
var process = Process.Start("calc.exe");
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(process_Exited);
process.SynchronizingObject = this;
textBox1.Text = "Main Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString();
Console.Read();
}
void process_Exited(object sender, EventArgs e)
{
MessageBox.Show("Process Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString());
}
}
}