Windows Phone 7上的Dispatcher.Invoke()?

Lem*_*ngs 4 dispatcher windows-phone-7

在回调方法中,我试图获取textBox的text属性,如下所示:

string postData = tbSendBox.Text;
Run Code Online (Sandbox Code Playgroud)

但是因为它没有在UI线程上执行,所以它给了我一个跨线程的异常.

我想要这样的东西:

Dispatcher.BeginInvoke(() =>
{
    string postData = tbSendBox.Text;
});
Run Code Online (Sandbox Code Playgroud)

但这是异步运行的.同步版本是:

Dispatcher.Invoke(() =>
{
    string postData = tbSendBox.Text;
});
Run Code Online (Sandbox Code Playgroud)

但是Windows Phone不存在Dispatcher.Invoke().有没有相当的东西?有不同的方法吗?

这是整个功能:

public void GetRequestStreamCallback(IAsyncResult asynchronousResult)
    {
        HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

        // End the operation
        Stream postStream = request.EndGetRequestStream(asynchronousResult);

        string postData = tbSendBox.Text;

        // Convert the string into a byte array.
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        // Write to the request stream.
        postStream.Write(byteArray, 0, postData.Length);
        postStream.Close();

        // Start the asynchronous operation to get the response
        request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
    }
Run Code Online (Sandbox Code Playgroud)

Mat*_*uGD 9

不,你是对的,你只能访问异步的.你为什么要同步,因为你在UI的另一个线程上?

Deployment.Current.Dispatcher.BeginInvoke(() =>
       {
            string postData = tbSendBox.Text;
        });
Run Code Online (Sandbox Code Playgroud)