2
我使用HttpWebRequest
類異步,如下圖所示(它的一個Windows應用程序)的HttpRequest給參數AsyncCallback委託
private void StartWebRequest(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(FinishWebRequest), request);
}
private void FinishWebRequest(IAsyncResult result)
{
HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
int num = 100000;
byte[] buffer = new byte[num];
int offset = 0;
while ((num2 = responseStream.Read(buffer, offset, 1000)) != 0)
{
offset += num2;
}
MemoryStream stream = new MemoryStream(buffer, 0, offset);
Bitmap bitmap = (Bitmap)Image.FromStream(stream);
bitmap.Save(@"z:\new.jpg");
response.Close();
responseStream.Close();
stream.Close();
}
但我想從StartWebRequest
方法給予一定的參數給AsyncCallback
代表,它是可能?因爲我想拍攝照片的名稱作爲參數,如:
bitmap.Save(@"z:\MYPARAMATERVALUE.jpg");