How the Deployment.Current.Dispatcher.BeginInvoke work in windows store app?

可紊 提交于 2019-12-06 03:30:57

Have you tried using this instead of the Deployment.Current.Dispatcher.BeginInvoke

CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
      {

      });

EDIT:

The whole method then being:

private async void OnChangesSaved(IAsyncResult result)
{
    bool errorFound = false;
    CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
      {
        this._context = result.AsyncState as THA001_devEntities;
        try
        {
            // Complete the save changes operation.
            this._context.EndSaveChanges(result);
        }
        catch (DataServiceRequestException ex)
        {
            errorFound = true;
            MessageBox.Show("Error, While Updating Record");
        }

        if (!errorFound)
        {
            MessageBox.Show("Record Successfully Updated");
        }
      });
}

this is what i re write, please approve the syntax

public void ModfityJobs(EquipBooking equipBooking)
        {
            try
            {
                this.IsDataLoaded = true;
                _context.BeginSaveChanges(ModfityJobsAsynchCallBack, equipBooking);
            }
            catch (Exception ex)
            {
            }
        }

        private void ModfityJobsAsynchCallBack(IAsyncResult synchresult)
        {
            try
            {
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                    {
                        _context.EndSaveChanges(synchresult);
                    });
            }
            catch (Exception)
            {

                throw;
            }
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!