problem while removing tab from a tabcontrol c#

Asked

Viewed 27 times

0

I’m trying to remove a tabcontrol, this tabcontrol is with the cef open (browser with google Chrome engine) in it I have a button called exit. He’s raised that way:

TabPage nova = new TabPage();
nova.Text = "aba1"; //aba 2 assim por diante
tabControl1.Controls.Add(nova);
chromeBrowser.Add(new ChromiumWebBrowser("http://sitedoprojeto.com/index.html"));
tabControl1.SelectedIndex = tabControl1.Controls.Count-1;
chromeBrowser[chromeBrowser.Count - 1].Parent = tabControl1.SelectedTab;
chromeBrowser[chromeBrowser.Count - 1].RegisterJsObject("cefCustomObject", new CefCustomObject(chromeBrowser[chromeBrowser.Count - 1], this, nova));

I have tried several ways, passing the last parameter above "new", also tried to pass to him chromeBrowser[chromeBrowser.Count - 1]. Parent, and also already tried to remove directly the selected tab, all attempts resulted in the error below: An explanation in code:

in javascript call the way out cefCustomObject.();

In the script cefCustomObject I call it so:

public void sair()
{
     _instanceMainForm.sair(_instanceTabPage);
}

And in the form I get so:

public void sair(TabPage _instanceTabPage)
    {
        //aqui removo os dados do sistema e entao da erro nesse comando
        tabControl1.Controls.Remove(_instanceTabPage);
    }

System.Invalidoperationexception: 'Invalid threading operation: 'control' accessed from a thread that is not the one in which it was created.'

Someone knows how I fix it?

  • I managed to solve

1 answer

0

I resolved so

if (tabControl1.InvokeRequired)
            tabControl1.BeginInvoke((MethodInvoker)delegate {
                tabControl1.Controls.Remove(_instanceTabPage);
            });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.