Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. static variable in a namespace

static variable in a namespace

Scheduled Pinned Locked Moved ASP.NET
help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joindotnet
    wrote on last edited by
    #1

    Hi all, I want to know is there any difference in the functioning of static variables defined inside a class library to that defined in a codebehind class. I came across such a situation when both of these are working differently.The codebehind one maintains single copy for all instance of that page and changes made at 1 place are being reflected in all the other places. where as the class library's one doesn't reflect the change smade to it except for the MOzilla browser. Is there somebody already faced and foud the solution to this problem.Please be kind enough to tell me answer. Thank you

    N 1 Reply Last reply
    0
    • J joindotnet

      Hi all, I want to know is there any difference in the functioning of static variables defined inside a class library to that defined in a codebehind class. I came across such a situation when both of these are working differently.The codebehind one maintains single copy for all instance of that page and changes made at 1 place are being reflected in all the other places. where as the class library's one doesn't reflect the change smade to it except for the MOzilla browser. Is there somebody already faced and foud the solution to this problem.Please be kind enough to tell me answer. Thank you

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Static variables stay in memory until the application domain where it is hosted unloads. So the static variables declared in a code behind file and a separate class library should work similarly. Is this library creates a new app domain?

      joindotnet wrote:

      where as the class library's one doesn't reflect the change smade to it except for the MOzilla browser.

      Browsers don't have any role in this. static variables are kept on servers memory and managed by the runtime. Make sure your ASP.NET process is not recycling frequently.

      Navaneeth How to use google | Ask smart questions

      J 1 Reply Last reply
      0
      • N N a v a n e e t h

        Static variables stay in memory until the application domain where it is hosted unloads. So the static variables declared in a code behind file and a separate class library should work similarly. Is this library creates a new app domain?

        joindotnet wrote:

        where as the class library's one doesn't reflect the change smade to it except for the MOzilla browser.

        Browsers don't have any role in this. static variables are kept on servers memory and managed by the runtime. Make sure your ASP.NET process is not recycling frequently.

        Navaneeth How to use google | Ask smart questions

        J Offline
        J Offline
        joindotnet
        wrote on last edited by
        #3

        Hi thanks for replying.Could u plz tell me why changes I make to the static variable are not reflected on IE but reflected on Mozilla??? I am confused.

        N G 2 Replies Last reply
        0
        • J joindotnet

          Hi thanks for replying.Could u plz tell me why changes I make to the static variable are not reflected on IE but reflected on Mozilla??? I am confused.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          joindotnet wrote:

          Could u plz tell me why changes I make to the static variable are not reflected on IE but reflected on Mozilla???

          I don't know. Have you tried pressing Ctrl + F5? Sometime IE's cache will be making problem.

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          • J joindotnet

            Hi thanks for replying.Could u plz tell me why changes I make to the static variable are not reflected on IE but reflected on Mozilla??? I am confused.

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            As the browser has nothing to do with how the static variable is stored, you are looking for the problem in the wrong place. The variable is changed just fine, it's just that you don't see the current value in the browser, probably because you are looking at a cached page.

            Despite everything, the person most likely to be fooling you next is yourself.

            J 1 Reply Last reply
            0
            • G Guffa

              As the browser has nothing to do with how the static variable is stored, you are looking for the problem in the wrong place. The variable is changed just fine, it's just that you don't see the current value in the browser, probably because you are looking at a cached page.

              Despite everything, the person most likely to be fooling you next is yourself.

              J Offline
              J Offline
              joindotnet
              wrote on last edited by
              #6

              Hi Guffa, Thanks for bothering.But I have set my browser to refresh every time a page is requested.It never sees the cached value....What might be the problem here I don't understand. Has this something to do with dll and AppDomain???'coz 1 variable is defined in the dll,other 1 is in normal codebehind.

              G 1 Reply Last reply
              0
              • J joindotnet

                Hi Guffa, Thanks for bothering.But I have set my browser to refresh every time a page is requested.It never sees the cached value....What might be the problem here I don't understand. Has this something to do with dll and AppDomain???'coz 1 variable is defined in the dll,other 1 is in normal codebehind.

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                A static variable is a static variable regardless of where in the application it is. There is only one instance of each static variable in the application, shared between all threads. If you change the value in a static variable and don't see the change, it's because you are not reading the variable at all. Static variables are usually not useful in a web application, as it's a multi threaded application, and all threads share the same static variable. If one user changes the variable, all users see the change.

                Despite everything, the person most likely to be fooling you next is yourself.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups