Hi Lau,
Thanks for your followup.
As for the two questions you mentioned, here are my suggestions in line
1) Iframe posting back: Isn’t this vulnerable? If the user navigates away
from the page in the middle of the sending process? It is critical that all
mails are send!
============================================
yes, if we're using a iframe to constantly post back and send mail, we
should display the sending status on the waiting page and tell the user not
to navigate away. Also, we have to log the currently sended mails(count) in
some application level variables.
2) How do I start a background thread?
==========================================
In asp.net we can start a background thread just like in desktop app. And
we can communicate with the background thread via ApplicationState
variables( to pass datas or event control the thread's lifetime. Here is
two demo pages:
==============start send mail page(code behind code
snippet)=================
private void btnSend_Click(object sender, System.EventArgs e)
{
try
{
Application["sendedcount"] = 0;
Application["completed"] = false;
Application["abortsending"] = false;
ThreadStart start = new ThreadStart( Send );
Thread t = new Thread( start );
t.Priority = ThreadPriority.Lowest;
t.Start();
//give it a second or two to start
Thread.Sleep( 2000 );
Response.Redirect( "checkstatus.aspx" );
}
catch(Exception ex)
{
Response.Write("<br>" + ex.ToString());
}
}
public void Send()
{
for(int i=0;i<1000;i++)
{
bool abort = (bool)Application["abortsending"];
if(abort)
{
break;
}
int count = (int)Application["sendedcount"];
//put the sending mail code here
count++;
Application["sendedcount"] = count;
Thread.Sleep(500);
if(count == 1000)
{
Application["completed"] = true;
}
}
}
===========checkstatus.aspx(we can put it in a iframe)===========
private void Page_Load(object sender, System.EventArgs e)
{
bool finished = (bool)Application["completed"];
if(finished)
{
Response.Write("<br>Finished sending 1000 mails!");
}
else
{
int count = (int)Application["sendedcount"];
Response.Write("<br>Has sended " + count + " mails!");
}
}
private void btnAbort_Click(object sender, System.EventArgs e)
{
Application["abortsending"] = true;
}
#checkstatus page will postback itself once after several seconds
===============================
Hope helps. If you have anything unclear, please feel free to post here.
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)