M
MattB
Hello
I am starting a new thread in a button click event.
This thread calls an method which sends emails, I don't want the page
to wait for the emails to finish going out as it slows the user down.
I have to set a session to null in the same click method but when
I do this I get this funny error.
"An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
Unknown Module.
Additional information: The type System.Web.HttpException in Assembly
System.Web, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a is not marked as serializable."
Here is a rough example of the code. There is no difference if I move
the Session=null
statement before or after the thread, or if I move the email code into
a separate class.
private void MultipleAttachEmail_Click(object sender, System.EventArgs
e)
{
ThreadStart ts = new ThreadStart(multipleMail);
Thread thread = new Thread(ts);
thread.Start();
Session["BasketSession"] = null;
Response.Redirect("DocBasketCheckout.aspx?%^="+EmailAddress.Text);
}
private void multipleMail ()
{
MailMessage msgMail = new MailMessage();
msgMail.To = EmailAddress.Text;
msgMail.From = "(e-mail address removed)";
msgMail.Subject = "Document Basket Contents";
msgMail.BodyFormat = MailFormat.Text;
msgMail.Body = " ";
// Gets document location path from Document Basket.
foreach(DataGridItem dgi in documentDataGrid.Items)
{
string dLink = baseURL + dgi.Cells[2].Text;
msgMail.Attachments.Add(new MailAttachment(Server.MapPath( dLink
)));
}
SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.Send(msgMail);
}
I am starting a new thread in a button click event.
This thread calls an method which sends emails, I don't want the page
to wait for the emails to finish going out as it slows the user down.
I have to set a session to null in the same click method but when
I do this I get this funny error.
"An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
Unknown Module.
Additional information: The type System.Web.HttpException in Assembly
System.Web, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a is not marked as serializable."
Here is a rough example of the code. There is no difference if I move
the Session=null
statement before or after the thread, or if I move the email code into
a separate class.
private void MultipleAttachEmail_Click(object sender, System.EventArgs
e)
{
ThreadStart ts = new ThreadStart(multipleMail);
Thread thread = new Thread(ts);
thread.Start();
Session["BasketSession"] = null;
Response.Redirect("DocBasketCheckout.aspx?%^="+EmailAddress.Text);
}
private void multipleMail ()
{
MailMessage msgMail = new MailMessage();
msgMail.To = EmailAddress.Text;
msgMail.From = "(e-mail address removed)";
msgMail.Subject = "Document Basket Contents";
msgMail.BodyFormat = MailFormat.Text;
msgMail.Body = " ";
// Gets document location path from Document Basket.
foreach(DataGridItem dgi in documentDataGrid.Items)
{
string dLink = baseURL + dgi.Cells[2].Text;
msgMail.Attachments.Add(new MailAttachment(Server.MapPath( dLink
)));
}
SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.Send(msgMail);
}