Multi-Threading w/ASPNET_WP

bri189a

Senior Contributor
Joined
Sep 11, 2003
Messages
1,004
Location
VA
I'm not advocate of multi-threading in ASP.NET - in most cases a better design can avoid the situation, and truth be known, I'm not an expert at multi-threading - everything I've multi-threaded has been in a fairly safe envrionment and was easy to deal with, however I've come across a situation that as far as I can tell calls for multi-threading. My question though is:

If I spawn a seperate thread in my application to kick off a long running process, and the main (originating) thread encounters an error or something that kills the aspnet_wp (say someone changed the web.config file) before the seperate thread is finished completing and joins back up with the main thread - will that other thread that was working now become lost memory? (Memory Leak).

Could I overcome this in the Application_Error event in Global by forcing a Thread.Join at this point? - Ditto for Application_End?.

What are some things to watch out for and code for in your experiance to keep from crashing the server?

Thanks!
 
Out of interest what is the need for threading in this case? Where possible you might be able to use .Net's more generalised Async methods (Beginxxx, Endxxx) rather than managing the threads yourself.
Also as your using .Net 2 you may want to look at the new functionality provided by the framework to make this easier; in the @Page directive set the Async="true" attribute and you should now be able to use the built in support (search MSDN for ExecuteRegisteredAsyncTasks as a starting point).
 
Last edited:
Back
Top