WP7 & Skydrive WaitOne blocking everything

180 Views Asked by At

I'm trying to download a file from SkyDrive and have wrapped the Asynchronous calls in a Synchronous class. However when I'm call WaitOne everything is blocked and the EventHandeler never gets called.

 _client = new LiveConnectClient(connection.Session);
 _client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_GetCompleted);
 _client.GetAsync("me/skydrive/files");

 _autoEvent.WaitOne();  //get's stuck here client_GetCompleted never called.

....


void client_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
{
    ///do stuff
    _autoEvent.Set();
}
2

There are 2 best solutions below

0
On

Remove the _autoEvent.WaitOne() call and the get completed event will be raised.

0
On

More than likely you are blocking the UI thread. (posting more code would help) Try running the first part in a new non-ui thread:

System.Threading.ThreadPool.QueueUserWorkItem(o =>
{
    _client = new LiveConnectClient(connection.Session);
    _client.GetCompleted +=
    new EventHandler<LiveOperationCompletedEventArgs>(client_GetCompleted);
    _client.GetAsync("me/skydrive/files");

   _autoEvent.WaitOne();  //get's stuck here client_GetCompleted never called.

   <other code>
});