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

D

Darrel

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
 
R

Rick Strahl \(MVP\)

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
 
D

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top