2013-09-22 42 views
0

我想更新我的頁面元素,但一些如何我的程序在更新過程中崩潰。 /*程序崩潰時更新元素

MainPage::MainPage() 
    { 
     InitializeComponent(); 
     ApplicationData::Current->DataChanged += ref new TypedEventHandler<ApplicationData^, Object^> 
     (this, &MainPage::DataChangedHandler); 
    } 

    void MainPage::DataChangedHandler(Windows::Storage::ApplicationData^ appData, Object^) 
    { 
     this->UpdateUIElements(); 
    } 

*/

+0

請發佈有關此問題的更多詳細信息 - 例如?錯誤信息 – Nogard

回答

0

的問題是,你需要在UI線程異步運行的更新。

void MainPage::DataChangedHandler(Windows::Storage::ApplicationData^ appData, Object^) 
{ 
    Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler(
     [this]() 
     { 
     UpdateUIElements(); 
     })); 
}