473,549 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is anyone else using Public Modules with Public Variable in aspx

Having weird things happening with my code. Two users on at the same time
and data entered by one user is added into another users global variable.
global variable data being stored in session variable between pages. any
ideas?
Jan 25 '06 #1
5 1429
I have used the following to avoid contention...
' The following is used to synchronize access to the global variable
SyncLock GetType(Global)
Global.TotalLog ins = Global.TotalLog ins + 1
End SyncLock
"Steve Mauldin" wrote:
Having weird things happening with my code. Two users on at the same time
and data entered by one user is added into another users global variable.
global variable data being stored in session variable between pages. any
ideas?

Jan 25 '06 #2
I sounds like maybe you need to use Session variables instead...

"Steve Mauldin" wrote:
Having weird things happening with my code. Two users on at the same time
and data entered by one user is added into another users global variable.
global variable data being stored in session variable between pages. any
ideas?

Jan 25 '06 #3
in a module, both private and public fields are shared between all threads
(concurrent requests), because all module fields (variables not defined
inside a function/sub) are shared by default. variables defined in
functions/subs are on the local stack, so they are not shared.

you could use attributes to make them thread local storage (like vb6), but
then you'd have to guarantee an asp.net request was handled by a single
thread (not the default) at a performance loss.

-- bruce (sqlwork.com)

"Steve Mauldin" <st**********@h otmail.com> wrote in message
news:eY******** ******@TK2MSFTN GP10.phx.gbl...
Having weird things happening with my code. Two users on at the same time
and data entered by one user is added into another users global variable.
global variable data being stored in session variable between pages. any
ideas?

Jan 25 '06 #4
What about variables defined in a class?
as in Current Account in the example below
Public Class CheckoutCustomi zation

Inherits UIX.Interior_No UC

Private CurrentAccount As Account

.........

end class
"Bruce Barker" <br************ ******@safeco.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
in a module, both private and public fields are shared between all threads
(concurrent requests), because all module fields (variables not defined
inside a function/sub) are shared by default. variables defined in
functions/subs are on the local stack, so they are not shared.

you could use attributes to make them thread local storage (like vb6), but
then you'd have to guarantee an asp.net request was handled by a single
thread (not the default) at a performance loss.

-- bruce (sqlwork.com)

"Steve Mauldin" <st**********@h otmail.com> wrote in message
news:eY******** ******@TK2MSFTN GP10.phx.gbl...
Having weird things happening with my code. Two users on at the same time and data entered by one user is added into another users global variable. global variable data being stored in session variable between pages. any
ideas?


Jan 25 '06 #5
Followup. It is my recommendation to anyone developing ASP.NET 1.1 not to
use Publuc Variables in Public Modules and specifically not to use them in
conjunction with session variables. Data persists from on persons session
to anothers and I had sessions overwriting each others data. The code to
duplicate this persistence is quite simple and is attached below (Special
Thanks to KJ for posting the code to duplicate). An interesting side point
is if you were wanting to share data between different users then this would
be a quick and fast way of doing it at the application level since you would
not have to redim or reload the data before using it. Everyone is pointing
to the same point in memory and the pointer stays across sessions. I can
see a use for it in gaming environments already. :)


*** code follows ***
' Module code

Module TestModule1
Public GlobalSettingsI nstance As New GlobalSettings
End Module

Public Class GlobalSettings
Public Int1 As Int32 = Int32.MinValue
End Class

'aspx #1

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
GlobalSettingsI nstance.Int1 = 567
'Session("GSI") = GlobalSettingsI nstance 'tried with this commented
and uncommented
End Sub

Private Sub lbtnGoToPage2_C lick(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles lbtnGoToPage2.C lick
Response.Redire ct("TestPage2.a spx", False)
End Sub

'aspx #2
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Response.Write( "Hello World") 'breakpoint here reveals .Int1 member =
567, regardless of session call in aspx #1
End Sub
"Steve Mauldin" <st**********@h otmail.com> wrote in message
news:eY******** ******@TK2MSFTN GP10.phx.gbl...
Having weird things happening with my code. Two users on at the same time
and data entered by one user is added into another users global variable.
global variable data being stored in session variable between pages. any
ideas?

Jan 26 '06 #6

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

Similar topics

7
1867
by: Harry J. Smith | last post by:
In my program VPCalc, Public procedures in a Form are not visible to other Modules. Is this how it should be? -Harry http://home.netcom.com/~hjsmith
5
3496
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to be really clever and use : #if subsearch ... #else ..... #end if
9
2368
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone...
15
2399
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
3
1093
by: Dan | last post by:
Hi guys I have an aspx page that accepts a posted to field, the id number of a product. On the page it then loads the details and allows editing of the product with a save button. The save button fires off sql to save the changes using that id number posted. My problem i had was that between postbacks the id number was not retained.
15
2562
by: Pucca | last post by:
I'm getting an error when I tried to use this BerConverter class in my C# code. Even though the Interent doc says that it runs on Win2000 sp4, I just thgouth I'll double check. Does anyone know if BerConverter is supported for Win2000 server? http://msdn2.microsoft.com/en-us/library/system.directoryservices.protocols.berconverter.decode.aspx...
9
1871
by: Coleen | last post by:
Hi All :-) I am desperately looking for some help/information on how to direct page flow. Forget what I have done - here's what I need to do: I have a large ASPX.Net - VB.Net web application (around 35-40 pages) that once the user logs in, I need to direct them to the correct page, depending on what they select from the directory. In...
2
2883
by: zaidalin79 | last post by:
r03581x has been helping me with a program, but he won't be online till Monday, and I have to have this finished by tomorrow... Is there anyone else out there that can help me? Here is the first half of what I have so far... I will post the rest of the code in a second post cause it is too long... import java.util.*; import javax.swing.*;...
11
1964
by: Ken Fine | last post by:
I am using VS.NET 2008 and like it a lot. One of the very few things I don't like is a bug that seems to spawn literally thousands of   strings, one after the other, on design view changes. Sometimes I will end up with as many as 30,000 of them. I have to do a "Replace" which is slower than I'd like. This is slowing down my work a lot. This...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7450
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...
0
7720
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. ...
0
7957
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...
0
6043
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...
1
5368
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...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
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

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.