async web service just don't get it

T

Tom

public class Client
{
public Server svr;

public void callbackMethod(IAsyncResult asyncResult)
{
svr.EndAsyncMethod(result)
}
[STAThread]
static void Main(string[] args)
{
svr = new Server();
object stateobj = new object();
Callback cb = new AsyncCallback(this.callbackMethod);
svr.BeginAsyncMethod(cb, stateobj);
}
}here's the code sambple above.. I don't get it.. what is the poing of new
AsyncCallback(this.callbackMethod); ? sorry but all this seems extremely
bloated to me right now.why make a call to
AsyncCallback(this.callbackMethod); with a reference of method in the
current class ?is it saying make callbackMethod async ?and why is there a
svr.EndAsyncMethod(result) in callbackMethod ?sorry just don't get itThanks
 
R

Richard Blewett [DevelopMentor]

The idea is that the main thread queues the webservice request to the thread pool and then can get on with other things. The webservice request actually runs on a threadpool thread. When the webservice returns teh data (which, the idea is, a potentialy time consuming operation that the main thread doesn't want to wait for) the threadpool calls the callback method. This can now pick up the results of the webservce call, by calling EndAsyncMethod on the webservice proxy, and process them.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

public class Client
{
public Server svr;

public void callbackMethod(IAsyncResult asyncResult)
{
svr.EndAsyncMethod(result)
}
[STAThread]
static void Main(string[] args)
{
svr = new Server();
object stateobj = new object();
Callback cb = new AsyncCallback(this.callbackMethod);
svr.BeginAsyncMethod(cb, stateobj);
}
}here's the code sambple above.. I don't get it.. what is the poing of new
AsyncCallback(this.callbackMethod); ? sorry but all this seems extremely
bloated to me right now.why make a call to
AsyncCallback(this.callbackMethod); with a reference of method in the
current class ?is it saying make callbackMethod async ?and why is there a
svr.EndAsyncMethod(result) in callbackMethod ?sorry just don't get itThanks
 

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

Top