私は非同期呼び出しを使用してWebサービスからデータを取得しているページを持っています。 Webサービスコントロールからの応答が得られたら、メッセージボックスがどこにあるかをキャッチするようになります。 コードは以下の通りです:Webサービスがあるときに、ページがロードされるときに それがWebサービスからデータをフェッチを開始(ケースを考えてみます。この部分はメッセージボックスが間違ったページでポップする
private void HandleForecastResponse(IAsyncResult asyncResult)
{
try
{
// get the state information
ForecastUpdateState forecastState = (ForecastUpdateState)asyncResult.AsyncState;
HttpWebRequest forecastRequest = (HttpWebRequest)forecastState.AsyncRequest;
// end the async request
forecastState.AsyncResponse = (HttpWebResponse)forecastRequest.EndGetResponse(asyncResult);
Stream streamResult;
string newCityName = "";
//int newHeight = 0;
// get the stream containing the response from the async call
streamResult = forecastState.AsyncResponse.GetResponseStream();
// load the XML
XElement xmlWeather = XElement.Load(streamResult);
}
catch (Exception ex)
{
MessageBox.Show("Connection Error");
}
}
問題応答である
string uri = "http://free.worldweatheronline.com/feed/weather.ashx?key=b7d3b5ed25080109113008&q=Mumbai&num_of_days=5";
UriBuilder fullUri = new UriBuilder("http://free.worldweatheronline.com/feed/weather.ashx");
fullUri.Query = "key=b7d3b5ed25080109113008&q=Mumbai&num_of_days=5";
HttpWebRequest forecastRequest = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
// set up the state object for the async request
ForecastUpdateState forecastState = new ForecastUpdateState();
forecastState.AsyncRequest = forecastRequest;
// start the asynchronous request
forecastRequest.BeginGetResponse(new AsyncCallback(HandleForecastResponse), forecastState);
応答せず、制御は部分をキャッチする)。 一方、戻るボタンを押すかページを移動すると、新しいページのメッセージボックスがポップアップします。
どうすればいいですか?
おかげで、よろしく
このソリューションも機能しますが、それに対してストレートな解決策が見つかりました。 – Mohit