2

我在下面有使用 HttpClient 的代码,但现在我想使用 Windows Azure 移动服务。我的应用程序没有发布,因为他们说我没有检查连接。有什么简单的方法可以做到这一点?

   private void StackPanel_Loaded(object sender, RoutedEventArgs e)
    {
        SystemTray.ProgressIndicator = new ProgressIndicator();

        //try to ping service before getting high scores
        try
        {
            SetProgressIndicator(true);
            SystemTray.ProgressIndicator.Text = "Loading...";

            GetHighScores(); //?????????

          //  HttpClient httpClient = new HttpClient();
          //  HttpResponseMessage response = await httpClient.GetAsync("http://punkoutersoftware.azurewebsites.net/api/drunkmeterscore");
          //  response.EnsureSuccessStatusCode();

            SetProgressIndicator(false);
        }
        catch (HttpRequestException e)
        {
            MessageBox.Show("High Scores not available at the moment");
        }

    }

    private async void GetHighScores()
    {
        try
        {
            scores = await scoreTable.OrderByDescending(x => x.Score).ToCollectionAsync();
        }
        catch (MobileServiceInvalidOperationException e)
        {
            MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
        }

        ListItems.ItemsSource = scores;
    }
4

1 回答 1

1

我怀疑使用无响应的 Azure 移动服务进行的验证过程测试。他们可能在没有数据连接的情况下进行测试。您可以在执行任何可能需要数据连接的操作之前检查数据连接,如下所示:

if(!DeviceNetworkInformation.IsNetworkAvailable)
{
   // inform user to get a data connection
}
于 2013-10-25T17:52:13.313 回答