windows-phone-7 – Windows Phone 7上的Dispatcher.Invoke()?
发布时间:2020-12-14 02:09:23 所属栏目:Windows 来源:网络整理
导读:在回调方法中,我试图获取textBox的text属性,如下所示: string postData = tbSendBox.Text; 但是因为它没有在UI线程上执行,所以它给了我一个跨线程的异常. 我想要这样的东西: Dispatcher.BeginInvoke(() ={ string postData = tbSendBox.Text;}); 但这是异
在回调方法中,我试图获取textBox的text属性,如下所示:
string postData = tbSendBox.Text; 但是因为它没有在UI线程上执行,所以它给了我一个跨线程的异常. 我想要这样的东西: Dispatcher.BeginInvoke(() => { string postData = tbSendBox.Text; }); 但这是异步运行的.同步版本是: Dispatcher.Invoke(() => { string postData = tbSendBox.Text; }); 但是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,postData.Length); postStream.Close(); // Start the asynchronous operation to get the response request.BeginGetResponse(new AsyncCallback(GetResponseCallback),request); } 解决方法
不,你是对的,你只能访问异步的.你为什么要同步,因为你在UI的另一个线程上?
Deployment.Current.Dispatcher.BeginInvoke(() => { string postData = tbSendBox.Text; }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-server-2008-r2 – 将Ctrl-Alt-Del发送到嵌套的RDP
- 如何在另一个appdomain中加载dll的配置文件
- Tridion工作流程插件在Microsoft Visio 2010中不活动
- iis – 如何衡量支持TLS 1.2的访问者的细分?
- win-universal-app – 无法访问Windows Universal Applicat
- 在Windows上正确设置OpenSSH的用户权限?
- .net – Windows身份验证的简单索赔转换和缓存
- 想知道Windows Clipboard Internals
- windows-xp – GnuPG:“解密失败:秘密密钥不可用”错误从
- vs2015+qt5.9.7配置跨平台的工程
推荐文章
站长推荐
热点阅读