asynchronous callbacks



I have a few processor intensive methods in my webservice which I need
to call from my web application.
After completion of these processes I need notification of whether
they were successful or not.

I can do this with delegates and by using BeginInvoke to update the UI
in a windows app but I can't
quite figure out how to do this in a web app.
This is what I have so far.

private void Button1_Click(object sender, System.EventArgs e)
AsyncCallback cb = new AsyncCallback(this.callback);
IAsyncResult ar = svcs.BeginProcess(this.TextBox1.Text, cb, svcs);

public void callback(IAsyncResult ar )
localhost.TestService svcs;
svcs = (localhost.TestService)ar.AsyncState;

bool reply = svcs.EndProcess(ar);

// Need to update UI
// #################



bruce barker

this will not work with a web page. while may look like a
windows app it not. the browser requests an html page, and send
one back. if the user clicks a button, thats just another request, the
page class is created, events called, html produced then sent back to
the browser.

if your page starts an async process and does not stall until complete
(say in pre-render or onload) then when the async completes, the browser
has already received the response html and closed the connection.

to do what you want your page need to start a background thread (should
use a pool) that processes the aync process. then have the browser poll
for completion with a javascript or a meta refresh tag.

-- bruce (


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