473,785 Members | 3,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Shared Functions

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 ?

Nov 18 '05 #1
3 1803
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" <Ar***@humsoft. com> wrote in message
news:bq******** *****@news.t-online.com...
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 ?


Nov 18 '05 #2
"Ford Prefect alias Armin" <Ar***@humsoft. com> wrote in message
news:bq******** *****@news.t-online.com...
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...

--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #3
"Ford Prefect alias Armin" <Ar***@humsoft. com> wrote in message
news:bq******** *****@news.t-online.com...
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...

--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1962
by: MPF | last post by:
When designing a n-tier architecture, what is the preferred method/function accessibility? <Specifically for asp.net apps> A private constructor and shared/static methods & functions? A public constructor and non-shared/static methods & functions? Are there any drawbacks with regards to performance with either model? Thanks,
13
2222
by: Bijoy Naick | last post by:
My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions. Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these. Questions - - How would I "include" this class in each aspx page?
2
1664
by: Henry | last post by:
Hi guys, I want to write some global functions which can be called from different asp.net page. In Visual Basic, there is a global module which allow me to do that. In Visual Basic .net, I have to create a class file to host these functions. And every time when I need to call these functions, I have to create a object.
11
3362
by: tshad | last post by:
I am setting up some of my functions in a class called MyFunctions. I am not clear as to the best time to set a function as Shared and when not to. For example, I have the following bit manipulation routines in my Class: ******************************************************************************* imports System NameSpace MyFunctions
4
45175
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the syntax for some of these functions have been set up with the keywords "Public Shared Function" (for example, the Trim function) and others are set up just as "Public
4
3362
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as interface member implementation?! Is there a workaround to this problem?! Best regards, Philippe Rubbrecht
8
1272
by: gemel | last post by:
I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures. With regard to object programming I assumed that variables declared within a class were private to the class, each object would have access to it's ver own copy of that variable. With regard to the methods defined for a class, I assumed that these are shared among all objects of the class, the code acting on the instances own copy...
5
4395
by: Confused ! | last post by:
I am writing an ASP.NET application and I want to use shared members on the data layer to retreive information from the SQL Server. If I declare a Function to be Shared, how will this affect things in a multi user environment. In other words, are my shared classes for the want of a better word. "Instantiated" for each user. Hope this makes sense ! --
1
1186
by: Nathan Sokalski | last post by:
I have a class that is just a bunch of Shared functions (basically, a bunch of utilities I have grouped together). However, there are functions that I want to write to use inside some of these Shared members that I do not want available outside the class. Here is the basic layout of my class: Public Class Utilities Public Shared Function Utility1() As String End Function
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.