Question

I have to deal with legacy ASP.NET application written in .NET Framework 1.1. When checking the application code I found interesting part. The application starts custom thread in Application_Start event handler (Global.asax). This thread must run whole life of the application.

Long time ago I read that this should be never used but I don't remember why. What are the problems related to such application design? Is it possible to start thread again when it crashes? Will the crash be logged somewhere automatically (event log)? Can ASP.NET runtime kill the thread for any reason?

At the moment I'm not interested in AppPool recycling. It restarts application, all sessions and creates new thread.

Was it helpful?

Solution

The main problem is that the thread may be terminated at any time by ASP.NET. If the thread's running the whole time, there is presumably some work it should be doing, and getting terminated may not make your application happy the next time it starts up.

Modern solutions include using asynchronous pages and the built-in thread pool.

If you do choose to upgrade, remember that in .NET 1.1, threads throwing a top-level exception just exit; in .NET 2.0, threads throwing a top-level exception crash. If you upgrade, it would probably be better to make the leap to async pages rather than keeping a separate thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top