I'm trying to wrap my head around asynchronous calling of methods.
public IDictionary<string, int> DoSomething(string startsWith)
{
return new Dictionary<string, int>();
}
public IAsyncResult BeginDoSomething(string startsWith, AsyncCallback callback,
object state)
{
return new Func<string, IDictionary<string, int>>(DoSomething)
.BeginInvoke(startsWith, callback, state);
}
public IDictionary<string, int> EndDoSomething(IAsyncResult result)
{
// How to return the IDictionary?!
}
My problem is that I have no idea how to get the IDictionary in the EndDoSomething method. I googled around and saw that some people use the state and callback, while others create their own class that derives from IAsyncResult, return it from Begin and cast to it in End.
Is that really the proper way to do it? Or what would be the proper way?