What happens to the Global variable when a new client joins the party?
Is it re initialised so all existing clients then see the re initialised value or does the new client inherit the current Global variable value?
For example if you wanted to know the number of clients could you have a global variable initialised at zero and incremented when the new client joins (runs the app in their browser)
Eg if I declare in Program.cs
internal static int Calls = 0;
Will it be reset to zero whenever a new client connects?
If this is the case how do you prevent a global variable from reinitialising?
Thanks
Ewan
Hi Ewan,
Variables declared as “static” in Wisej are available across all client sessions. You would be able to determine how many clients are connected by using one.
Beware of how this works, if you close all instances of the application and then immediately proceed to create a new session, the static variables will still retain all of the information from the previous sessions. The value does not reset until all instances of the application running on the clients are closed and the IIS app pool restarts, IIS crashes, or the server is rebooted. Be careful with what kind of information you’re storing in the variable and be sure to reset it when appropriate.
For storing client-specific information, I would recommend using the Application.Session dynamic object.
For more information about sessions check out the documentation:
https://wisej.com/docs/2.1/html/Session.htm
Does this help clarify?
Best,
Levie
