A
Arthur Dzhelali
I am trying dynamically create controls and add them to the form on the
Separate thread.
I know that I have to use delegate in order to update preexisting
controls on the form, but when I ma trying create new control I am
getting this message:
System.ArgumentException: Controls created on one thread cannot be
parented to a control on a different thread.
this is a sample code to reproduce error:
Delegate Sub MyDelegate()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dd As New MyDelegate(AddressOf addctrl)
For i As Int32 = 0 To 10
Try
dd.BeginInvoke(Nothing, Nothing)
Catch ex As Exception
End Try
System.Threading.Thread.Sleep(500)
Next
End Sub
Sub addctrl()
Try
Dim x As New TextBox
Me.Controls.Add(x)
Debug.WriteLine(Me.Controls.Count)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
End Sub
is there any way around it?
basicaly I have dataset which is updated and repopulated on the separate
thread and the it raises event and form gets recreated. IS there a way to
marshal event to proper thread??
any Ideas
Separate thread.
I know that I have to use delegate in order to update preexisting
controls on the form, but when I ma trying create new control I am
getting this message:
System.ArgumentException: Controls created on one thread cannot be
parented to a control on a different thread.
this is a sample code to reproduce error:
Delegate Sub MyDelegate()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dd As New MyDelegate(AddressOf addctrl)
For i As Int32 = 0 To 10
Try
dd.BeginInvoke(Nothing, Nothing)
Catch ex As Exception
End Try
System.Threading.Thread.Sleep(500)
Next
End Sub
Sub addctrl()
Try
Dim x As New TextBox
Me.Controls.Add(x)
Debug.WriteLine(Me.Controls.Count)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
End Sub
is there any way around it?
basicaly I have dataset which is updated and repopulated on the separate
thread and the it raises event and form gets recreated. IS there a way to
marshal event to proper thread??
any Ideas