2

我是 Windows Phone 7 和 C# 的新手。我面临导航到新屏幕的问题。我的要求是我需要检查服务器的登录凭据,如果可以,则进入下一个屏幕。但我收到错误为“UnauthorizedAccessException” -“无效的跨线程访问”。.

在下面找到代码

 private void button1_Click(object sender, RoutedEventArgs e)
    {     
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(uri));
        request.ContentType = "application/x-www-form-urlencoded";
        request.Method = "POST";
        request.BeginGetResponse(ResponseCallback, request);
    }   

  private void ResponseCallback(IAsyncResult asynchronousResult) 
    {
        var request = (HttpWebRequest)asynchronousResult.AsyncState;
        var response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

        if (response.StatusCode  == HttpStatusCode.OK)
        {
            this.NavigationService.Navigate(new Uri("/tabview.xaml", UriKind.Relative));
        }
    }
4

1 回答 1

1

尽管 OP 已经解决了他的问题,但这篇MSDN 文章详细解释了其背后的基本原理。

于 2012-07-26T19:53:06.350 回答