Skip to main content
 首页 » 编程设计

c#线程访问其他线程

2024年02月13日12kenshinobiy

<分区>

我有这个错误:跨线程操作无效:“控制‘progressBar1’是从创建它的线程以外的线程访问的。”我似乎无法弄清楚如何修复它。

    private void button1_Click(object sender, EventArgs e) 
    { 
        this.panel1.Visible = false; 
        this.panel2.Visible = true; 
        new Thread(ProgressBAR).Start(); 
    } 
    private void ProgressBAR() 
    { 
        Thread.Sleep(5); 
        for (int start = 0; start <= 100; start++) 
        { 
            this.progressBar1.Value = start; 
            Thread.Sleep(5); 
        } 
    }