I\'m porting some code from the full .NET framework to the WP7 version and I\'m running into an issue with synchronous vs async calls.
string response;
str
First I suggest trying to get comfortable with async but if you really want/need to convert an asynchronous call to a synchronous you can use ManualResetEvent
to achieve the desired result.
Here is a quick example if usage:
public ManualResetEvent _event = new ManualResetEvent(false);
...
{
...
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(ReadCompleted);
wc.OpenReadAsync(uri);
// block until async call is complete
_event.WaitOne();
}
private static void ReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
...
// set event to unblock caller
_event.Set();
}
Now you code will block on the line _event.WaitOne();
until _event.Set();
is called.
Good Luck!