Using Shared Functions

  • Thread starter Thread starter Ford Prefect alias Armin
  • Start date Start date
F

Ford Prefect alias Armin

Hello

I use SHARED Sub's and Functions to access Data from all running Sessions.

I use the KeyWord Shared in the Functions of the Class.

This is working fine.. an I can share Data between all Sessions.

Are there any known Problems with this in Web ?
Is this the right way ?

Will it maybe slow down the speed ?

I needed something like a Session Variable but one that run's endless
and is not shutdown after 20 Minutes so I did it that way ?


Who would you do this ?
 
Static classes and methods (Shared keyword in Visual Basic .NET) are the
means Microsoft uses for caching items. For application settings, static
properties are a great way of storing information. Just make sure the object
never falls out of scope, or you can get into trouble.

For session related items, do not use Static properties (static (helper)
methods are okay), as you will end up with user(s) resetting values for all
other user(s).

For web apps, you can also use the application object to store items, which
essentially does the same thing. Whether one is better than the other
largely deals with the application at hand.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Ford Prefect alias Armin said:
Hello

I use SHARED Sub's and Functions to access Data from all running Sessions.

I use the KeyWord Shared in the Functions of the Class.

This is working fine.. an I can share Data between all Sessions.

Are there any known Problems with this in Web ?

Just keep in mind that because these Shared variables can be accessed from
multiple sessions, they can be accessed from multiple sessions AT THE SAME
TIME. You will need to use locking when you update them. For instance:

Private Shared counter As Integer = 0
Public Shared Sub IncrementIt
Dim c As Integer
c = counter
c = c + 1
counter = c
End Sub

This will not do what you would expect. Imagine having two threads executing
the "c = counter" or "counter = c" lines at the same time...
 
Back
Top