Click here to Skip to main content
15,170,651 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
today someone told me that when using the async pattern it is possible to use
public DataTable EndCall(IAsyncResult ar)

in stead of
public void EndCall(IAsyncResult ar)

is this true? because in the BeginEventHandler an error is given.

In this case a HttpModule is used. That registers the begin and end handler in IIS and IIS handles the async call. This async httpmodule calls a proxy class and that call a wcf service. Even the proxy has generated async methods based on the methods in the wcf service.
Updated 28-Sep-11 21:59pm
Jimmanuel 28-Sep-11 14:48pm
If you're implementing the Async method yourself then yes it's possible, but more info would be needed to diagnose your exact problem. What's the error? More code please.
Ed Nutting 28-Sep-11 16:02pm
Agree with Jimmanuel - it depends very much on situation - like most things really :)

1 solution

Yes it is possible to get a return value when using async methods. So if we had a method such as ..

private string Foo()
  return "Hello"

and a delagate like this ..

public delegate string MyDelegate();

You can use code like this to get the result.

MyDelegate del = new MyDelegate();
IAsyncResult res = del.BeginInvoke();

// Do something while our method is being executed

string result = delFoo.EndInvoke(res);
[no name] 29-Sep-11 7:39am
Good Answer. My 5!

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