I want to interact with a control on my main Form (Ui thread). But it is not working, and I need your help!
I use the following code on my main Form:
delegate sub AddObjectsToFolvDelegate(byref list As List(Of source)) 'delegate
public Sub AddObjectsToFolv(byref value As List(Of source)) 'invoke
Try
msgbox(folvsource.IsHandleCreated.ToString) 'Always false, on UI thread true
If me.InvokeRequired Then 'Always false
Dim d As New AddObjectsToFolvDelegate(AddressOf AddObjectsToFolv)
me.invoke(d, value)
Else
me.folvsource.AddObjects(value) 'Add Objects to Objectlistview
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
And on the other Class I use the following code to call the invoke:
FrmMain.AddObjectsToFolv(proxysites)
If I check if a invoke is requiered to access the control from a worker thread it always returns false. So if I then check if the handle is created it also returns false (on worker thread).
The thread was started from my main Form after it was compleatly loaded (shown).
I also tried to manually create my control with folvSource.CreateControl()
If I call the invoke I get the error message (cause the handle of the control(s) is not created inside my worker thread):
invoke or begininvoke cannot be called on a control until the window handle has been created
I create new threads using the following code with the SmartThreadPool libray on my main Form:
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'msgbox(import.TestAdd("").ToString)
dim imp as New Import
dim MajorPool As New SmartThreadPool
MsgBox(
MajorPool.QueueWorkItem(New WorkItemCallback(AddressOf imp.TestAdd), "").GetWorkItemResult.GetResult().
ToString())
End Sub