110,546
社区成员
发帖
与我相关
我的任务
分享
private void button2_Click(object sender, EventArgs e)
{
try
{
prc = Process.Start(this.textBox2.Text.Trim());
if (prc != null)
{
this.Invoke(new Action(delegate
{
this.textBox1.Text = prc.Id.ToString();
}));
prc.EnableRaisingEvents = true;
prc.Exited += prc_Exited;
}
}
catch (ArgumentException)
{
MessageBox.Show("not find the Process!\r\nplease you confirm the process's ID is correct!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void prc_Exited(object sender, EventArgs e)
{
prc = null;
if (Guard == true)
{
button2_Click(null, null);
}
}
prc.Exited += prc_Exited;
if (Guard == true)
{
button2_Click(null, null);
}
这里当然会进入死循环吧