How to implement an asynchronous code?
-
Hello, Into my asp.net application every day i download an xml file and store the values in my database. After did this, i display this xml file using an aspx page. After displaying, an e-mail is sent to 2000 users who are subscribe to this info. My problem is that i want to dipslay first the page to confirm there is no problem, then send the e-mail but because i use Response.Redirect function my code for sending e-mail is never run. If i send first the e-mail, i must wait for the end (5 minutes) before displaying xml value into my page. Therefore i would to display my page and execute at the same time the function to send e-mail or sending the e-mail in asynchronous mode. The part of my code with this problem is the following :
'Storing data in my database
iRes = mydb.DBRecordPublication(strFilename, sDate, snumero, sDoc)
If iRes >= 0 Then
'Displaying data on screen
Dim NomMagazine As String = strFilename
Response.Redirect("ShowNews.aspx?News=" & NomMagazine & "&DateNews=" & sDate & "&ConnecString=" & mydb.GetConnectionString())
'Sending e-mail : Never run after Response.Redirect
Dim strRes As String = myMail.SendSommaire(Me.Context)
end ifthanks in advance for any help
-
Hello, Into my asp.net application every day i download an xml file and store the values in my database. After did this, i display this xml file using an aspx page. After displaying, an e-mail is sent to 2000 users who are subscribe to this info. My problem is that i want to dipslay first the page to confirm there is no problem, then send the e-mail but because i use Response.Redirect function my code for sending e-mail is never run. If i send first the e-mail, i must wait for the end (5 minutes) before displaying xml value into my page. Therefore i would to display my page and execute at the same time the function to send e-mail or sending the e-mail in asynchronous mode. The part of my code with this problem is the following :
'Storing data in my database
iRes = mydb.DBRecordPublication(strFilename, sDate, snumero, sDoc)
If iRes >= 0 Then
'Displaying data on screen
Dim NomMagazine As String = strFilename
Response.Redirect("ShowNews.aspx?News=" & NomMagazine & "&DateNews=" & sDate & "&ConnecString=" & mydb.GetConnectionString())
'Sending e-mail : Never run after Response.Redirect
Dim strRes As String = myMail.SendSommaire(Me.Context)
end ifthanks in advance for any help
Although you can implement an aysnc page you may be better using Ajax. Display the page with a button to send the emails. The button will call an Ajax function that will send the emails. A side benefit is you can get updates on the number of emails sent, if you code it that way.
No comment