Dispatcher.Invoke() on Windows Phone 7?

◇◆丶佛笑我妖孽 提交于 2019-12-05 16:34:27

No you are right you can access only to the async one. Why do you want sync since you are on a different thread of the UI one?

Deployment.Current.Dispatcher.BeginInvoke(() =>
       {
            string postData = tbSendBox.Text;
        });

This should make an asynchronous call to a synchronous :

  Exception exception = null;
  var waitEvent = new System.Threading.ManualResetEvent(false);
  string postData = "";
  Deployment.Current.Dispatcher.BeginInvoke(() =>
  {
    try
    {
      postData = tbSendBox.Text;
    }
    catch (Exception ex)
    {
      exception = ex;
    }
    waitEvent.Set();
  });
  waitEvent.WaitOne();
  if (exception != null)
    throw exception;

1) Obtain a reference to the synchronization context of UI thread. For example,

SynchronizationContext context = SynchronizationContext.Current

2) Then post your callback to this context. This is how Dispatcher internally works

context.Post((userSuppliedState) => { }, null);

Is it what you want?

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