سؤال

I am trying to update my page elements but some how my program crashes during update. /*

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

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

*/

هل كانت مفيدة؟

المحلول

The problem is you need to run the update asynchronously in the ui thread.

void MainPage::DataChangedHandler(Windows::Storage::ApplicationData^ appData, Object^)
{
    Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler(
        [this]()
        {
        UpdateUIElements();
        }));
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top