473,378 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1420
I have used the following to avoid contention...
' The following is used to synchronize access to the global variable
SyncLock GetType(Global)
Global.TotalLogins = Global.TotalLogins + 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**********@hotmail.com> wrote in message
news:eY**************@TK2MSFTNGP10.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 CheckoutCustomization

Inherits UIX.Interior_NoUC

Private CurrentAccount As Account

.........

end class
"Bruce Barker" <br******************@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP14.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**********@hotmail.com> wrote in message
news:eY**************@TK2MSFTNGP10.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 GlobalSettingsInstance 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.EventArgs) Handles MyBase.Load
GlobalSettingsInstance.Int1 = 567
'Session("GSI") = GlobalSettingsInstance 'tried with this commented
and uncommented
End Sub

Private Sub lbtnGoToPage2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles lbtnGoToPage2.Click
Response.Redirect("TestPage2.aspx", False)
End Sub

'aspx #2
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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**********@hotmail.com> wrote in message
news:eY**************@TK2MSFTNGP10.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
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
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...
9
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 -...
15
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...
3
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...
15
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...
9
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...
2
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...
11
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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.