Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 windows phone 7中的跨线程访问无效?_Windows Phone 7 - Fatal编程技术网

Windows phone 7 windows phone 7中的跨线程访问无效?

Windows phone 7 windows phone 7中的跨线程访问无效?,windows-phone-7,Windows Phone 7,在上面的代码Messagebox.show dispalying“无效的跨线程访问”中。请告诉我如何解决此问题…任何与UI的代码交互都需要在dispatcher线程上,HTTP请求的回调将不会在此线程上运行,因此会出现错误 您应该能够使用类似 Deployment.Current.Dispatcher.BeginInvoke(()=>MessageBox.SHow(“成功”)) 显示消息框的步骤 鲁伯特 void GetResponseCallback(IAsyncResult asynchro

在上面的代码Messagebox.show dispalying“无效的跨线程访问”中。请告诉我如何解决此问题…

任何与UI的代码交互都需要在dispatcher线程上,HTTP请求的回调将不会在此线程上运行,因此会出现错误

您应该能够使用类似

Deployment.Current.Dispatcher.BeginInvoke(()=>MessageBox.SHow(“成功”))

显示消息框的步骤

鲁伯特

void GetResponseCallback(IAsyncResult asynchronousResult)
        {

            try
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                string responseString = streamRead.ReadToEnd();

                XmlReader xmlDoc = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(responseString)));

                while (xmlDoc.Read())
                {
                    if (xmlDoc.NodeType == XmlNodeType.Element)
                    {

                        if (xmlDoc.Name.Equals("ResponseCode"))
                        {
                            responseCode = xmlDoc.ReadInnerXml();

                        }

                    }

                }
                if (Convert.ToInt32(responseCode) == 200)
                {

                   MessageBox.Show("Success");
                }


                // Close the stream object
                streamResponse.Close();
                streamRead.Close();
                // Release the HttpWebResponse
                response.Close();


            }
            catch (WebException e)
            {
                // Error treatment
                // ...
            }
        }
    Dispatcher.BeginInvoke(() =>
            MessageBox.Show("Your message")
    );