我对 C# 有点陌生,并且textbox
在异步方法中检索值时遇到了一些问题。我是在 UI 中检索文本输入并在代码中使用它的线程。VS 2010 接受我的代码,但是当我开始调试时,它给了我以下异常
Invalid cross-thread access
。想法?我错过了什么吗?
public void Response_Completed(IAsyncResult result)
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
{
JObject rootObject = JObject.Load(new JsonTextReader(streamReader));
string tracknum = trackid.Text; // Invalid cross-thread access exception
string source = rootObject[tracknum]["source"].ToString();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//removed
});
}
}
注意:我正在尝试在 Windows Phone 7 平台上执行此操作