Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello!

I'm trying to use a async Delegate to show and populate a form but the form show up and stays Not Responding.

Normally the form opens OK when it's sync with the code.

Example situation:
Before Class:
VB
Public Delegate Sub MyAsyncDelegate()


In primary sub:
VB
Dim del As MyAsyncDelegate
del = New MyAsyncDelegate(AddressOf SubToExecute)
Dim cb As AsyncCallback = New AsyncCallback(AddressOf CodeComplete)
Dim ar As IAsyncResult = del.BeginInvoke(cb, Nothing)


In CodeComplete sub:
Populate with SubToExecute values that I confirm that are ok and show another form that stay not responding.
Posted
Updated 19-Sep-11 15:00pm
v2
Comments
Herman<T>.Instance 20-Sep-11 6:55am    
TIP: del.BeginInvoke(cb, Nothing) should be del.BeginInvoke(cb, del). In that case you maintain thread safety. You keep your state. In the CodeComplete method you can do:
Dim del As MyAsyncDelegate
del = (MyAsyncDelegate)ar.AsyncState
You have your delegate values back

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900