0

我有一个异步请求触发另一个网页进行一些处理代码如下。我对此有一些问题。我希望请求被触发,然后忽略直到它完成,然后当它完成时,我想触发一封电子邮件。

回调似乎永远不会触发。我错过了什么?

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();
    }
}
4

0 回答 0