async web service just don't get it

  • Thread starter Thread starter Tom
  • Start date Start date
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
 
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
 
Back
Top