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 5998707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:26:39+00:00 2026-05-23T00:26:39+00:00

Here is my scenario. I have an ASP.NET MVC solution with 3 projects. Data,

  • 0

Here is my scenario.

I have an ASP.NET MVC solution with 3 projects. Data, Web, and Windows Service. The Data layer has static (non thread safe) properties which goes and gets data once otherwise stores in static private field. See below:

    private static int? _userCount;
    public static int UserCount
    {
        get
        {
            if (!_userCount.HasValue)
            {
                _userCount = GetUserCount();
            }

            return _userCount.Value;
        }
        set
        {
            _userCount = value;
        }
    }

This works great for my needs. In the Web layer I call into a Service method in my data layer whenever adding a new user and set UserCount = NULL Thus the next time there is a hit to the site it will go fetch a fresh count. This works as expected too.

I also have a Windows Service which can create Users via an import process. It calls into the same SaveUser method as the web layer which again should be Nulling out the UserCount property. I would then think I should be able to be on the website and refresh the page and have it again get a new user count. However this is not the case.

I can step through the code and see the Service hit the UserCount = NULL but its like the web layer doesn’t recognize it even though it is calling into the same property.

I have to do an IIS Reset anytime the Windows Service brings in a User in order to clear out the static properties. Any thoughts on why this would behave differently with creating the user in the Service vs. on the Web layer via the UI?

  • 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-23T00:26:40+00:00Added an answer on May 23, 2026 at 12:26 am

    Let me see if I have this straight. You have a library that handles save user, which nulls out a count value. It works in MVC, but not in your windows service, because it is not being seen as null in your MVC application.

    If I have that correct, let me be more explicit. You have a library to handle users being used by your MVC application. The same library is also being used by a windows service.

    If I have that correct, did you get the reason things are not working. If you are stuck on static, start thinking process boundaries and ask “Is the MVC application using the same process as the windows service”?

    Short answer: If this functionality is in a library, used by two separate applications, it is behaving correctly, as each application stores its own shared and instance bits in its own process space. It is nulling out, but only for the service.

    Cure? Have the windows service call a method in the MVC application to indicate it has changed things is certainly one option. Another is to use a different method of invalidating user count when values have changed.

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

Sidebar

Related Questions

I have a question that has pretty much been asked here: asp.net mvc Html.ActionLink()
Here's the scenario: I have an asp.net webpage which displays dynamic data in a
Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data
Here's the scenario I have an ASP.NET 4.0 application which has a LOT of
Here's the scenario: You have an ASP.Net application supported by a Microsoft SQL Server
So, here's the scenario : I have a page in my asp.net c# based
So here is the scenario: I am working with ASP.NET MVC 2 under the
Here is the scenario: I have two asp pages. a.aspx is layout and b.aspx
Here's the scenario: You have a Windows server that users remotely connect to via
Here's the scenario: I have a textbox and a button on a web page.

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.