WP7& Skydrive WaitOne阻止了一切

时间:2012-07-11 04:18:23

标签: windows-phone-7 onedrive waitone

我正在尝试从SkyDrive下载文件并将异步调用包装在Synchronous类中。但是,当我调用WaitOne时,一切都被阻止,EventHandeler永远不会被调用。

 _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 个答案:

答案 0 :(得分:0)

删除_autoEvent.WaitOne()调用,将引发get完成事件。

答案 1 :(得分:0)

您很可能阻止了UI线程。 (发布更多代码会有所帮助) 尝试在新的非ui线程中运行第一部分:

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>
});