跨线程操作无效:从不是在其上创建线程的线程访问控件“ tabControl1”

时间:2018-08-06 11:39:56

标签: c# multithreading thread-safety invokerequired

嗨,我在我的项目中使用cefsharp,在创建类并通过线程开始工作后,给我这个错误,请帮助我修复。 我的班级:

    public void InitializeChromium()
    {
        CefSettings settings = new CefSettings();
        // Initialize cef with the provided settings
        Cef.Initialize(settings);
        // Create a browser component
        chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com");
        // Add it to the form and fill it to the form window.
        web_tab = new TabPage();
        web_tab.Controls.Add(chromeBrowser);
        web_tab.Text = "Thread";            
        tab_con.TabPages.Add(web_tab);
        //Invoke(new Action(() => ));
        //chromeBrowser.Dock = DockStyle.Fill;
    }

我的项目:

        private void button1_Click(object sender, EventArgs e)
    {
        Browser_Class f1 = new Browser_Class();
        f1.tab_con = tabControl1;            
        Thread mythread = new Thread(f1.InitializeChromium);            
        mythread.Start();


    }

0 个答案:

没有答案