delegates

B

barry

I have a exercise in understanding delegates using beginInvoke and
endInvoke. It runs fine on the windows platform but when I copy the exact
same code into asp.net while it runs without any errors it is not getting
from the worker thread back to the main UI. The code is below. Is there
something specifically differnent in using delegates on the web? Thanks for
any help.

this is all on webform1.aspx.vb
Public Delegate Function DoneDelegate(ByVal stopped As Boolean) As Boolean

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

Dim s As Boolean

s = False

Dim cb As New AsyncCallback(AddressOf AllDone)

Dim del As New DoneDelegate(AddressOf CountStuff)

del.BeginInvoke(s, cb, del)

End Sub

Sub AllDone(ByVal ar As IAsyncResult)

Dim del As DoneDelegate

del = CType(ar.AsyncState, DoneDelegate)

lblResults.Text = (del.EndInvoke(ar) & " records found")


End Sub

Public Function CountStuff(ByVal stopped As Boolean) As Boolean

Dim intOut As Boolean = True

System.Threading.Thread.Sleep(5000)

Return intOut

End Function
 
S

Scott Allen

Barry:

Once the flow of control leave the Click event handler - it will
eventually reach the Render method. It's quite possible the entire
form will render and be done by the time your asynch call finishes.
You really have no choice but to block and wait for the asynch call to
finish if you need the results for display (which might make you
reconsider if you need an asynch call at all in asp.net).
 
B

barry

Thanks this really helps
Scott Allen said:
Barry:

Once the flow of control leave the Click event handler - it will
eventually reach the Render method. It's quite possible the entire
form will render and be done by the time your asynch call finishes.
You really have no choice but to block and wait for the asynch call to
finish if you need the results for display (which might make you
reconsider if you need an asynch call at all in asp.net).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top