So here I am,got some help from some web tutorials and performing following Asynchronous call. I want to return an object of type UserInfo from following async call. But I'm not sure how the program flows after request.BeginResponse(). Is it something like an additional ref parameter of type UserInfo can be passed to callback method?
UserInfo GetUserInfoAsync()
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Credentials = new NetworkCredential("myID", "myPWD");
request.Method = "GET";
request.Accept = "application/json";
object data = new object();
RequestState state = new RequestState(request, data, url);
IAsyncResult asr = request.BeginGetResponse(new AsyncCallback(myCallback), state);
return null; //Need guidence here;
}
private static void myCallback(IAsyncResult result)
{
RequestState state = (RequestState)result.AsyncState;
WebRequest request = (WebRequest)state.Request;
HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(result);
Stream s = response.GetResponseStream();
StreamReader readStream = new StreamReader(s);
string dataString = readStream.ReadToEnd();
response.Close();
s.Close();
readStream.Close();
UserInfo ui = ParseJSON(dataString );
}