Accessing GUI Thread

07/02/2011 00:01 sarkoplata#1
Hey guys,
I'm having problems with editing my gui,
i use vb.NET and for example i want to add something to my listbox from another thread.
I used a lot of invoke styles but everyone gives me
"BeginInvoke or Invoke cannot be called before window handle has been created."
btw, I have to do a lot changes so it should not sooo long.
I already checked CheckForIllegalCrossThreadCalls = False but it doesnt work =/ Waitin for ur helps..
07/02/2011 02:43 sarkoplata#2
Ok.. now i add some text to my listbox ^^
PHP Code:
 Public Shared Sub Log(ByVal oo As Object)
        
Application.OpenForms(0).Invoke(New MethodInvoker(Function()
                                                              
Main.LogBox.Items.Add("[" DateTime.Now.ToLongTimeString "]" oo)
                                                          
End Function)) 
But when i create same sub for changing a label's text, it doesnt work.
PHP Code:
 Public Shared Sub Log(ByVal oo As string labe as label)
        
Application.OpenForms(0).Invoke(New MethodInvoker(Function()
                                                              
labe.text=oo
                                                          End 
Function)) 
BUT If i create sub with only 1parameter again, no problems ; like this
PHP Code:
Public Shared Sub ChangeLabelText(ByVal oo As String)
        
Application.OpenForms(0).Invoke(New MethodInvoker(Function()
                                                              
Main.NameLabel.Text oo
                                                          End 
Function))
    
End Sub 
So.. will i create the sub again and again for each label?

sarkolata
07/02/2011 19:41 Kraizy​#3
PHP Code:
//Add a text to any label, for example when clicking a button:
Public Sub Button_Click()
     
Log(New Object() {Label1"myText"})
End Sub

//methods to invoke:
Private Delegate Sub testDel(cLabel as LabelText as String)

Public 
Sub Log(params() as Object)
     
Me.Invoke(New testDel(AddressOf invokeTest), params(0), params(1))
     
//params(0) = Label1
     //params(1) = "myText"
End Sub

Private Sub invokeTest(cLabel as LabelText as String)
     
cLabel.Text Text
End Sub 
But I did not try the code, maybe u will have to change something...