For many applications the Singleton Design Pattern approach
works fine. However, for multithreaded applications this approach proves to
have a potentially hazardous side effect. If two threads manage to enter the
control block at the same time, two instances of the member variable could be
created. To solve this you might be tempted to merely place a critical section
around the control block in order to guarantee thread safety.
However, ASP.NET runs each incoming request on its own
separate worker thread. The ASP.NET programming model is based on a scheme in
which each worker thread is routed through a private set of ASP.NET objects,
including applications, modules, pages, and custom handlers. The ASP.NET
programming model was designed to ensure that only one worker thread will ever
touch any one of these objects at any one time. This enhances productivity
because you can write most of your ASP.NET code as single-threaded. There is
no need to worry about concurrency or thread safety for the scenario described in
this article.