I am not a used C# programmer, so if this is stupid, sorry :-)
I am developing a C# app for Windows 8. I need to do a web request, and therefore, I have a callback to handle the request data.
I am using the standard approach:
private static ManualResetEvent allDone = new ManualResetEvent(false);
private static void daCallback(IAsyncResult data) {
...
SampleDataSource.allDone.Set();
}
// This is the Class CONSTRUCTOR
public SampleDataSource() {
# before anything, reset allDone:
string request = "http://some.url.com";
HttpWebRequest webRequest = WebRequest.Create(request) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.BeginGetResponse(new AsyncCallback(daCallback), webRequest);
Debug.WriteLine("Asked to begin get response");
SampleDataSource.allDone.WaitOne(12000);
Debug.WriteLine("Done Waiting");
#...
}
When running, allDone (inside do_something) is not initialized. I even added a condition around to compare allDone with null, and yep, it is null.
The "Done Waiting" message never gets print at all...
What am I doing wrong?
Thank you