Hi !
Ok below is the code which uses a delegate and also specify's a callback sub
now the callback sub should be on UI Thread if that is true then why does the below code do not work and it also does not give any kind of error
I have been struggling with delegates
any help would be greatly appreciated
Delegate Function dlg() As Boolean
Dim tvDlg As New dlg(AddressOf updatetv)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Passed the delegate into the BeginInvoke so it can be retrieved later.
tvDlg.BeginInvoke(New AsyncCallback(AddressOf updatecomplete), tvDlg)
End Sub
Function updatetv() As Boolean
Try
' TreeView1.Nodes.Add("ok")
'if i uncommnet the above line it will give a error that on a wrong thread , ok that is fine i understand that
Return True
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Function
Sub updatecomplete(ByVal ar As IAsyncResult)
Dim oDel As dlg
Dim bResult As Boolean
Dim objResult As AsyncResult
' Extract the delegate from the AsyncResult
objResult = CType(ar, AsyncResult)
oDel = objResult.AsyncDelegate
' Obtain the result
bResult = oDel.EndInvoke(ar)
' now this function is not wokring also there is no error
w()
End Sub
Function w()
TreeView1.Nodes.Add ("ok")
Debug.WriteLine("done")
End Function

Callback Delegate on UI thread?
bfellner