うまくいけば簡単にあなたのためのすべての質問が、私は本当に苦労しています。 私はちょうどプログラミングを開始したばかりで、WP7アプリストアに認定されたアプリを持っていましたが、アプリを公開する前に修正したいバグに気づきました。webclient非同期リクエストを取り消します
基本的に私はユーザーが化学名を入力し、Webサービスが画像とその分子量を返す検索ボックスを持っています。私がしたいのは、ダウンロードが完了する前にユーザーがページから離れて移動した場合、または前回の完了前に新しい検索が行われた場合にWebクライアントをキャンセルすることです(これは現在、1つのリクエスト時??)
private void searchCactus()
{
WebClient imgClient = new WebClient();
imgClient.OpenReadCompleted += new OpenReadCompletedEventHandler(imgClient_OpenReadCompleted);
WebClient mwClient = new WebClient();
mwClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(mwClient_DownloadStringCompleted);
if (DeviceNetworkInformation.IsNetworkAvailable == false)
{
MessageBox.Show("No network found, please check network availability and try again");
}
else if (compoundSearchBox.Text.Contains("?"))
{
MessageBox.Show("\"?\" Not Permitted");
return;
}
else if (compoundSearchBox.Text != "")
{
progBar1.IsIndeterminate = true;
string imageuri = "http://cactus.nci.nih.gov/chemical/structure/" + compoundSearchBox.Text + "/image?format=png&width=300&height=300";
string mwURI = "http://cactus.nci.nih.gov/chemical/structure/" + compoundSearchBox.Text + "/mw";
imgClient.OpenReadAsync(new Uri(@imageuri), imgClient);
mwClient.DownloadStringAsync(new Uri(@mwURI), mwClient);
// //lower keyboard
this.Focus();
}
else MessageBox.Show("Enter Search Query");
}
私は、次のボタンを実装しようとしたが、それはよう
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
imgClient.CancelAsync();
mwClient.CancelAsync();
}
動作しない「名 『mwClient』は現在のコンテキスト内に存在しない」
をもし誰かが提供できれば、私はとても感謝しています。いくつかのガイダンス
クラス内のフィールドに2つのクライアントを配置するだけです。 – svick
@svickは、私が予想していたよりも簡単でした。私はpublic partial class MWSearch:PhoneApplicationPageを追加しました。 { private WebClient imgClient; プライベートWebClient mwClient; ......それはあなたの意味ですか?もう一度ありがとう – shadyamigo