Is Threading Possible in an ASP.NET 1.1 Web Page?

F

Frank

Hi,

I am trying the following code with no success. Any input would be
appreciated.


private void InsertMsg( )

{

//do some stuff and then send an email in a new thread because our mail
server is slow many times and I want to redirect without waiting for email
to complete

Thread t = new Thread(new ThreadStart(Send_Email));

t.Priority = ThreadPriority.Highest;

t.Name = "MailThread";

t.Start();

Response.Redirect("threads.aspx?TopicID=" +
Request.QueryString["TopicID"] + "&TopicName=" +
Request.QueryString["TopicName"]);

}//End Function InsertMsg()



private void Send_Email()

{

//function sends email via SMTP

}



I tried creating and strting the thread in Page_Unload event but that didn't
work either.



Thanks for any input
 
K

Keith Patrick

Try declaring your thread outside the method. Once the method ends, that
thread should be de-allocated since its scope is being destroyed, so if it
doesn't finish before that request call is done, it's gonna end as well.
I'd either declare a worker thread member in your class or spawn off a
worker thread via ThreadPool (it'll be more efficient than
creating/destroying threads every time)
 
A

Alvin Bruney [MVP]

There's no reason why that code should fail. How do you know it is failing?
Don't set the thread priority to highest, that's a bad practice, leave it as
normal. Also, you should be using a thread pool for this, it will put a cap
on the number of threads being used. On a heavy day, that code will likely
bring down the server. Also, you need to remove the response redirect line
from that function. It isn't logically related to inserting a message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top