Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Normally, I will instantiate a class for global variables with a section like so:

 

Private m_FullName As String
   Private m_Identity As System.Security.Principal.WindowsIdentity
   Private m_URL As String

   Shared myInstance As globVars

   Private Sub New()

       m_Identity = System.Security.Principal.WindowsIdentity.GetCurrent()
       m_FullName = m_Identity.Name

   End Sub

   Public Shared Function GetInstance() As globVars
       If myInstance Is Nothing Then
           myInstance = New globVars
       End If
       Return myInstance
   End Function

'/ insert properties here

 

Then invoke the class:

 

Dim glob as globVars

 

glob = globVars.GetInstance

 

And start using variables.

 

This works over a network environment, but not so hot in an Internet environment, I believe because the Application doesn't really close if everyone is on it.

 

I tried setting the class to nothing in the Application.Close event - no luck.

 

Any ideas as to what I am doing or not doing wrong here?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

  • Administrators
Posted

Global variables and asp.net applications are a really difficult mix and you need to be very careful about how you use them.

 

Application variables will remain until the application exits and it's only then that the application_close event will fire. If you wish to remove the class when a user disconnects then the session_end may be a more appropriate place.

 

However you will probably still get the potential for problems with your code due to the use of shared data members. It may be easier to design the class to use instance data rather than shared data and then store it in either the application or session based on the requirements of your app.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...