2012-07-11 87 views
0

我試圖從SkyDrive下載一個文件,並在同步類中包裝了異步調用。然而,當我打電話給WaitOne時,一切都被阻止,EventHandeler永遠不會被調用。WP7&Skydrive WaitOne阻止了一切

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

回答

0

刪除_autoEvent.WaitOne()調用並引發get completed事件。

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