小编Ada*_*dam的帖子

运行另一个没有GUI冻结的进程

在运行(和等待)外部进程时,我无法让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();
            } …
Run Code Online (Sandbox Code Playgroud)

c# multithreading

5
推荐指数
1
解决办法
5703
查看次数

标签 统计

c# ×1

multithreading ×1