views:

11

answers:

0

hi folks,

I have this scenerio where i have to get some records, enumerate them, and send emails to the customers using a new thread in the appliction. Here is the code.

foreach (BookingDetail b in bookings)
        {
            StringWriter sw = new StringWriter();
            context.Server.("Emails/FeedbackEmail.aspx?BookingDetailId=" + b.DetailId.ToString(), sw);

            MailManager.SendAlert(context, false, "redered", "page rendered");

            string res = sw.ToString();
            string output = res.Substring(res.IndexOf("<table"));
            string Body = output.Remove(output.IndexOf("</form>"), 27);
            string To = "abc@abc"; //test email

            MailManager.SendAlert(context, false, "redered", "page rendered");

            SendEmail(context,
                MailManager.BOOKING_CONFIRMATION_EMAIL_ADDRESS,
                To,
                null, //MailManager.CLIENTS_ADDRESS,
                null, //BCC
                string.Format("Leave your feedback and WIN a pair of West End Show Tickets!"),
                Body);

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
        }

Now, everything works fine if I call this function directly without puting it in a new thread. As soon as I put it in a new thread, I get an exception at the line where it executes the feedbackemail.aspx page. Although the function is receiving the context and the page is being exucted wrt that context.

I do not want to write all the HTML inside the server side code so I'd prefer to execute the page. Please remember that it works fine without thread. BTW, I have not marked the thread as isbackground. Can someone please explain what's the benifit of doing so?

A little help will be appreciated.

Thanks,

J.