2
我有下面使用HttpClient的代碼,但現在我想使用Windows Azure移動服務..我的應用程序沒有發佈,因爲他們說我沒有檢查連接..什麼是一個簡單的方法來做到這一點?如何處理呼叫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;
}
聽起來很像和奇怪的問題,從來沒有聽說過。也許嘗試微軟論壇並在這裏發佈答案。因爲try和catch方法就是我通常使用的方法。 – JTIM
我認爲他們告訴你在啓動時檢查網絡連接?即如果您在使用之前檢查是否可以使用HttpClient。 –