我有一个异步请求,触发到另一个网页进行一些处理代码如下。我有一些问题。我希望将该请求解雇,然后忽略它直到完成,然后当它完成时,我想发射一封电子邮件。
似乎回调永远不会被解雇。我错过了什么?
private HttpWebRequest req = null;
private IAsyncResult result = null;
protected void btnUpload_Click(object sender, EventArgs e)
{
StringBuilder pageUrl = "http://myurl.example.com";
// Initialize web request
req = (HttpWebRequest)WebRequest.Create(string.Format("{0}", pageUrl.ToString()));
req.Method = "GET";
// Start the asynchronous request.
try
{
result = (IAsyncResult)req.BeginGetResponse(new AsyncCallback(RespCallback), null);
}
catch (Exception ex)
{
//lblProcess.Text += ex.Message.ToString();
}
}
protected void RespCallback(IAsyncResult ar)
{
using (WebResponse resp = req.EndGetResponse(ar))
{
//using (StreamReader reader = new StreamReader(resp.GetResponseStream())) {
// text = reader.ReadToEnd();
//}
//function that just sends an email
SendBatchEmail();
}
}