alpav
alpav

Reputation: 3062

Unexpected second AppDomain in ASP.NET website

One of my classes have static constructor that assigns new GUID to static variable. Then I use that variable for folder name that I create to store cached information for the lifetime of my website. The goal is to have different folder names when website is recycled or something else happens.

My website is running in IIS7 and is configured to have maximum one worker process. Recycling is disabled.

I use ThreadPool.QueueUserWorkItem to make multiple parallel database requests asynchronously and then ManualResetEvent.WaitOne() to merge those calls back to one thread. I use mentioned above folder to cache results of those requests.

My problem is that it appears that at some point I get 2 folders created and running at the same time. I understand that means that I get 2 AppDomains, not just one. I don't understand why do I get second AppDomain and what can I do to prevent it from happening.

Upvotes: 2

Views: 234

Answers (2)

Marcelo De Zen
Marcelo De Zen

Reputation: 9497

EDIT: This is not the answer if recycling is disabled, although the behavior below still will happen if you change web.config.

This problem probably happen when a recycle is made. The IIS7 will create a new worker process, wait for it to be read and only then it will shutdown the old one. So, for a briefly period of time of 5-30 seconds your application will be running in 2 worker processes.

You can disable this behavior by setting "Disallow overlapping recycling" to True on app pool Advance Settings...

Upvotes: 0

alpav
alpav

Reputation: 3062

As usual, the answer is simple and in different area - static members are different for each type of a class if it's a generic class.

http://www.codeproject.com/Articles/26514/Generic-Types-Don-t-Share-Static-Members

Upvotes: 2

Related Questions