Getting cross thread error when executing tcViewer.TabPages.Add(t)
statement.
Code is as below.
Private Function fff(t As TabPage)
tcViewer.TabPages.Add(t) 'giving cross thread error
End Function
Function WebBrowserThread()
Dim t As TabPage = New TabPage((k + 1).ToString())
t.Name = k.ToString()
tcViewer.Invoke(fff(t))
End Function
Please guide.
I think you should move the creation of the new
TabPage
onto the UI thread as well:When you construct the
TabPage
, you eventually reach this call stack:At this point, the
Handle
is being created, and if you're doing that on the wrong thread, everything else is going to start going wrong (because the thread that the control was created on isn't going to run a message pump)