小编Top*_*rak的帖子

应该第二个线程等待主线程

当我启动主线程时,我也启动了第二个线程,但第二个线程仍然等待主线程.我期望当我开始一个新线程时,它将在没有连接到主线程的情况下继续工作.那么为什么panel1在主线完成工作后变得可见?

    private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
    {
        Thread thread = new Thread(new ThreadStart(threadUI));
        thread.Start();

        // This class is loading something from the server on the main thread
        excel.get_data_from_excel(comboBox1.SelectedItem.ToString(), this);
    }
    private void threadUI()
    {
        if (panel1.InvokeRequired)
        {
            panel1.Invoke(new newDelegate(threadUI));
        }
        else
        {
            panel1.Visible = true;
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# multithreading

0
推荐指数
1
解决办法
137
查看次数

标签 统计

c# ×1

multithreading ×1