【发布时间】:2011-01-25 06:18:08
【问题描述】:
在运行(和等待)外部进程时,我无法让我的 GUI 出现并且不冻结。在这种情况下,drivers.exe 是一个非常简单的程序,用户只需单击“确定”即可。因此,每当我单击“确定”时,它就会退出。我正在尝试在执行 drivers.exe 时简单地增加我的状态条计数(非常快)。但实际上,在 drivers.exe 退出之前,我的 GUI 根本不会出现。
private void run_drivers()
{
Console.WriteLine("Start Driver");
int driver_timeout_in_minutes = 20;
System.Diagnostics.Process driverproc = System.Diagnostics.Process.Start(Application.StartupPath + "\\" + "drivers.exe");
driverproc.WaitForExit(driver_timeout_in_minutes * 1000 * 60); //uses milliseconds, we must convert
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart worker = new ThreadStart(run_drivers);
Console.WriteLine("Main - Creating worker thread");
toolStripStatusLabel1.Text = "hi";
Thread t = new Thread(worker);
t.IsBackground = true;
t.Start();
Console.WriteLine("Main - Have requested the start of worker thread");
int i = 0;
while (t.IsAlive)
{
i++;
toolStripStatusLabel1.Text = i.ToString();
}
Console.WriteLine("Dead");
}
【问题讨论】:
标签: c# multithreading