473,289 Members | 2,040 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,289 software developers and data experts.

Using public shared variables...asking for trouble with thread conflicts?

I'm working on an app where the ASPX pages aren't precompiled with the
class.vb files I'm. This is so people can add their own ASPX pages down the
road to the app (the .aspx pages become 'templates' in a way).

As such, each template has a function call at the top:

<% retrieveData() %>

and then within the page, wherever they want to show some text from the db,
they just use one of the variables sent in the vb file:

<%=pageTitle%>

My question is if my logic on the back end makes sense. Here's a general
outline of what I am using in the .vb file:

------------------------------------
Public Class retrieveData
Public Shared pageTitle As String
Public Shared contentTitle As String
Public Shared portfolioID As String
Public Shared pageContent As String

Public Shared Function getPageContentData()
Query = "SELECT * from Database where pageID =
HttpContext.Current.Request.QueryString("pg")
pageTitle = field from DB
contentTitle = field from DB
etc...
end function
end class
------------------------------------

This seems to work, and is very minimal code for the end-user of the ASPX
page to deal with. But is there anything wrong with my logic? Is there a
thread conflict issue where two people could hit two pages at the exact same
time mixing up the data?

-Darrel
May 17 '06 #1
2 2999
Hi Darrel,

I don't think the way you're using statics/shared vars is a good way here,
because multiple pages will writing this data to a single instance.

static data is 'singleton' - one instance which means all ASP.NET requests
share the same static properties across threads.

In your case I suspect you want to just use regular instance properties not
static values.

Why are you using the statics here in the first place?
+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog


"Darrel" <no*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I'm working on an app where the ASPX pages aren't precompiled with the
class.vb files I'm. This is so people can add their own ASPX pages down
the road to the app (the .aspx pages become 'templates' in a way).

As such, each template has a function call at the top:

<% retrieveData() %>

and then within the page, wherever they want to show some text from the
db, they just use one of the variables sent in the vb file:

<%=pageTitle%>

My question is if my logic on the back end makes sense. Here's a general
outline of what I am using in the .vb file:

------------------------------------
Public Class retrieveData
Public Shared pageTitle As String
Public Shared contentTitle As String
Public Shared portfolioID As String
Public Shared pageContent As String

Public Shared Function getPageContentData()
Query = "SELECT * from Database where pageID =
HttpContext.Current.Request.QueryString("pg")
pageTitle = field from DB
contentTitle = field from DB
etc...
end function
end class
------------------------------------

This seems to work, and is very minimal code for the end-user of the ASPX
page to deal with. But is there anything wrong with my logic? Is there a
thread conflict issue where two people could hit two pages at the exact
same time mixing up the data?

-Darrel

May 17 '06 #2
> I don't think the way you're using statics/shared vars is a good way here,
because multiple pages will writing this data to a single instance.

static data is 'singleton' - one instance which means all ASP.NET requests
share the same static properties across threads.
That's what I thought.
In your case I suspect you want to just use regular instance properties
not static values.
Why are you using the statics here in the first place?


Probably because I'm not entirely clear on the concept. ;o)

How does one use 'regular instance properties' in a case like this?

-Darrel
May 17 '06 #3

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

Similar topics

6
by: Paul | last post by:
Hi. Just trying to find out the best approach as I beleive it might give me problems later on down the road. I have an ASP.NET application which references a shared database class which...
1
by: Qingdong Z. | last post by:
Posted in asp.net newsgroup, no answer. Hope some experts can help me here 1. Does class shared variable share same feathers as ASP.NET application variable? 2. If it is, it may work better...
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 -...
3
by: Joe Fallon | last post by:
I have a Shared varibale in a base class and all the Shared methods in the sub-classes use it (and CHANGE it). I thought I was saving myself the "trouble" of Dimming this variable inside each...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
27
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
5
by: Steve Mauldin | last post by:
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...
4
by: Gregory Gadow | last post by:
I've cobbled together a PrinterClass that takes a text file and dumps it to a printer. The app using is has multiple threads, all of which need access to a shared instance. Can someone point me to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.