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

  • SEARCH
  • Home
  • 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 7494471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:33:59+00:00 2026-05-29T17:33:59+00:00

I have a question regarding static members and functions of non static classes. I

  • 0

I have a question regarding static members and functions of non static classes.

I have a static member in my class that I use for authentication. Basically I call a static function from my web application and then inside I call a static function that assigns a value to that static member. Now my question is, will each call to a static function from my web application create a new reference to the object and assign a new value to the static member.

So basically I have this:

public class ClassA
{
     private static int UserId;

     private static AssignIdToUser(string token)
     {
         UserId = <int value depending on result of db query>;
     }

     public SendMessage(string token, string message, string toaddress)
     {
         AssignIdToUser(token);
         Message msg = new Message(); //This is just a sample of a class that is similar to the one I use
         msg.Message = message;
         msg.UserId = UserId;
         msg.ToAddress = toaddress;
         //add class to db and save
     }
}

Then in my web application I can do:

ClassA.SendMessage("userstoken", "This is a message", "0123456789");

Now if two users log on at the same time and the function gets called at the same time will the member UserId have the correct value for each user?

Basically is a instance of the object created for each request or is the same object used?

  • 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-29T17:34:00+00:00Added an answer on May 29, 2026 at 5:34 pm

    An instance of the static member will exist for each AppDomain, unless you specify [ThreadStatic] in which case it will be per thread, but always per type (note, generics play on this point heavily!)

    Static members are not a good choice for web apps because IIS recycles AppDomains regularly. You’d lose the static each time it recycled.

    User actions are usually stored in Session state, I’d start here. Assuming ASP.NET:

    Session State on MSDN

    Application State on MSDN

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

Sidebar

Related Questions

Question regarding static variables in static classes. If i have a static class and
I have a question regarding static function in php. let's assume that I have
I have a question regarding class design. I want to have a class that
I have a question regarding the following code: abstract class a { public static
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have a question regarding dependency injection. say i want to create a class
I have a question regarding LinkedList that I'm using to implement a queue. How
I have two questions about static + const members and static classes. One: Why
I have a query regarding accessibility of top level class from member inner 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.