473,385 Members | 1,732 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,385 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 3002
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.