Adding tab page to tab control from non UI thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've been having a problem on trying add a tab page that are created on non
UI thread to a tab control. I understand that we need to use control.invoke
to invoke the execution on thread that created the control. The code is
working if I simply change a text box text, but not when I adding a tab page.
The exception that I got is "Control.invoke() must be used to interact with
controls created on a separate thread". Here is piece of the code.

Private Delegate Sub AddTabPageDelegate(ByVal tabPage As TabPage)

Private Sub FinishedPopulatingTabPage(ByVal tabPage As
System.Windows.Forms.TabPage) Handles Me.FinishedPopulatingTabPage
If _activeForm.TabControl1.InvokeRequired Then
_activeForm.Invoke(New AddTabPageDelegate(AddressOf AddTabPage),
New Object() {tabPage})
End If
End Sub

Private Sub AddTabPage(ByVal tabPage As TabPage)
_activeForm.TabControl1.TabPages.Add(tabPage)
'_activeForm.Label1.Text = "hello" & tabPage.Text
End Sub

Looks like there is a bug in the tabControl.tabPages.Add(). Any thoughts?

Thanks heaps
 
You have to create and manipulate all UI objects on UI thread only. That is,
tab page creation should be on UI thread as well.


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Back
Top