Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here are two things you could do: </p> <ol> <li>make GetResponseCallback not static, and <strong>store the xmlName in an instance variable</strong> </li> <li>pass a <strong>state object</strong> (anything that has a property named xmlName, and something else to identify it by) to the request, and you can get it from the <code>AsyncState</code></li> <li><p>change GetResponseCallback's function to the following, and make the <strong>whole thing a callback "factory"</strong></p> <pre><code>private static AsyncCallback GetResponseCallback(string xmlName) { return (IAsyncResult asynchronousResult) =&gt;{ HttpWebRequest httpRequest = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse response = (HttpWebResponse)httpRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseStream = streamRead.ReadToEnd(); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var istream = new IsolatedStorageFileStream(@"tmp" + xmlName + ".xml", FileMode.OpenOrCreate, store)) { using (var sw = new StreamWriter(istream)) { sw.Write(responseStream); } } } // Close the stream object streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); } } </code></pre></li> </ol> <p>EDIT to ADD:<br> the usage then changes to</p> <pre><code> httpRequest.BeginGetRequestStream(GetRequestStreamCallback(xmlName), httpRequest); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload