I have a normal method
public List<string> FindNearByCity(string targetCity)
{
// ... some implementation
}
I want to add async support for this method, so i wrote this:
public IAsyncResult BeginFindNearByCity(string targetCity, AsyncCallback callback, object obj)
{
Func<string, List<string>> method = FindNearByCity;
return method.BeginInvoke(targetCity, callback, obj);
}
public List<string> EndFindNearByCity(IAsyncResult result)
{
Func<string, List<string>> method = FindNearByCity;
return method.EndInvoke(result);
}
The BeginFindNearByCity works fine, however when it comes to EndFindNearByCity, exception will throw when it hit EndInvoke.
I look into the auto gen Async web service method, seems i need to implement something call “ChannelBase”
can anyone point me to something that more simple like tutorial or sample that i can have a look at?
Thanks
The delegate you are creating in your
EndXXXmethod is a separate instance to the delegate you create in yourBeginXXXmethod, therefore it has no knowledge of theIAsyncResultwhich you are passing to itsEndInvoke()method.You have to use the same delegate in the
EndXXXmethod as theBeginXXXmethod, e.g.