Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:03:21+00:00 2026-05-26T05:03:21+00:00

I am wondering if a static class in an ASP.NET MVC app could be

  • 0

I am wondering if a static class in an ASP.NET MVC app could be initialized more than once. I initially designed my app so that a static component would fetch some stuff from the database and serve as a cache, and I added a refresh method to the class which was called from the constructor. The refresh method was also made available through the administration portion of the app. At some point I noticed that the data was updated without requiring this manual trigger, which implies that the static constructor run more than once.

There are several scenarios where I could reasonably see this happen, such as an unhandled Exception causing re-initialization. But I am having trouble reproducing this, so I would like to know for sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:03:22+00:00Added an answer on May 26, 2026 at 5:03 am

    The most usual scenarios would be:

    • a reload of the web application

      • touched Web.config
      • touched binaries
      • abnormal termination (out-of-memory, permission errors)
    • a reload of the Application Pool

    • a restart of IIS
    • a restart of w3wp.exe (at least once in 29 hours!)

    The app-domain will get reloaded (recompiling the dynamic parts as necessary) and this would void any statically initialized data.

    You can get around that by persisting the static data somewhere if creating it is expensive, or avoid reloading the AppDomain, the Application Pool or the IIS server.

    Update: Phil Haack just published a relevant blog entry here: http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx

    • Bye Bye App Domain
      • it does a better job at explaining the above. Notable, IIS will recycle it’s worker process very 29 hours at minimum and shared hosters will recycle AppDomain much more often (perhaps in 20 minutes of idle time)
    • So tell ASP.NET, “Hey, I’m working here!”
      • outlines techniques you can apply to get notified of an AppDomain take down – you could use this to get your Singleton instance behaving ‘correctly’
    • Recommendation

    I suggest you read it 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 2 project that I'm working on and I'm wondering
Here's a little background on my solution: ASP.Net MVC app Using Linq-to-SQL with table-per-hierarchy
I'm totally new to the ASP.NET MVC stack, and I was wondering what happened
I created and love my Asp.Net MVC2 application. It's a very nice DDD app
I am developing a 3-tired ASP.NET C# web application and was wondering where should
I am wondering if it is possible to have a static class instantiate another
I'm working in a C# web service with a generic static class that takes
I'm developing a swing app which suits the MVC pattern and I'm wondering about
I work on a fairly large ASP .NET Web Forms application that is currently
So I was wondering if anyone could help me understand how the jQuery 'class'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.