I am developing an application using asp.net 2.0. I created all my
business objects in my app_code folder. As of right now, all my
classes are public.
In my aspx pages, I am declaring the class like so
static Person myPerson;
The static declaration is working for me, for It keeps the instance of
the class open through the lifetime of the user who is logged in.
However, I read that the reference remains open even after the user's
session, and it is probably not going to be thread safe? I want to
avoid storing it in a Session due to it being rather expensive on the
server. I could probably make the class private, and ensure that the
class is instantiated accordingly. Any suggestions from you experts? 2 2830
I believe any global object is not thread-safe by definition if you don't
synchronize access to fields/methods properly
If your Person is related to user/session, probably you would be better off
by making it in-session instance. Just destroy it when closing session and
you should be pretty safe.
<re********@yah oo.comwrote in message
news:11******** **************@ g4g2000hsf.goog legroups.com...
>I am developing an application using asp.net 2.0. I created all my
business objects in my app_code folder. As of right now, all my
classes are public.
In my aspx pages, I am declaring the class like so
static Person myPerson;
The static declaration is working for me, for It keeps the instance of
the class open through the lifetime of the user who is logged in.
However, I read that the reference remains open even after the user's
session, and it is probably not going to be thread safe? I want to
avoid storing it in a Session due to it being rather expensive on the
server. I could probably make the class private, and ensure that the
class is instantiated accordingly. Any suggestions from you experts? re********@yaho o.com wrote:
I am developing an application using asp.net 2.0. I created all my
business objects in my app_code folder. As of right now, all my
classes are public.
In my aspx pages, I am declaring the class like so
static Person myPerson;
The static declaration is working for me, for It keeps the instance of
the class open through the lifetime of the user who is logged in.
However, I read that the reference remains open even after the user's
session, and it is probably not going to be thread safe? I want to
avoid storing it in a Session due to it being rather expensive on the
server. I could probably make the class private, and ensure that the
class is instantiated accordingly. Any suggestions from you experts?
Thread safety is not a problem if you have data that is local to the
thread. A static variable however, is not local to the thread. What you
have is a single Person object that is shared by all threads, which
means that your application only can handle a single user.
Making it private makes no difference either. That only means that it's
private to the class where you declared it, not private to the thread.
If you want to store user specific data, you have to use user specific
storage, like Session variables.
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
Is a static method that uses local variables thread safe (eg in a web service)
In the following code assuming GetRandomValue() and DoSomethingElse() are thread safe, is the static method thread safe
public class Cach
public static int GetAValue(
int x = 0
x = GetRandomValue()
|
by: Simon Harvey |
last post by:
Hi all,
I'm considering using a the micorsoft data access block as the main DAC for
my application. A colleage of mine suggested that I might have a problem
with concurrency though
When a method is static, do I need to worry about concurrency?
I figured that microsoft would have had this in mind when making the
component. Obviously numerous users are going to be routing calls through
|
by: GG |
last post by:
Is this public static method thread safe.
//Receives a file name as a parameter
//and returns the contents of that file as a string
public static string FileToStr(string fileName)
{
FileStream fStream=null;
lock(fStream) //just in case we use it for multithreading to be thread
safe
{
|
by: Clint |
last post by:
Hey all -
Excuse the cross-post ... I'm not sure what the appropriate newsgroup
would be for this question.
I have a question that I'm not quite sure how to ask. For all I know, I
have the verbaige completely wrong, but here goes nothing ...
I'm currently using the MS Data Access Block for a desktop application
I'm writing. Recently, I had to add a call to a web service, which in
|
by: dee |
last post by:
OleDbCommand class like many .NET classes has the following description in
its help file:
"Thread Safety
Any public static (Shared in Visual Basic) members of this type are safe for
multithreaded operations. Any instance members are not guaranteed to be
thread safe."
I have 2 questions:
1. I thought dynamic variables are thread-safe since threads have their own
| |
by: Macca |
last post by:
Hi,
Are static variables thread safe? I have a static byte array. This will be
accessed from more than one thread. Is it automatically thread safe by being
static rather than an instance or do i need to write code to make it thread
safe?
Cheers
Macca
|
by: Shimon Sim |
last post by:
I have a static variable defined something like this
private static Dictionary<string, string> roles = new
Dictionary<string,string>();
Can I safely assume that it will be live for the live of application?
Meaning that any thread/page of the application will have access to the data
in this variable.
|
by: intrader |
last post by:
I have the following small classes:
//----------------code---------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ValidatorsLibrary
{
public class ValidatorBase
{
|
by: Laser Lu |
last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN.
The declaration is usually described as 'Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.'
So, does this mean All the static/shared methods written in .NET compatible programming language, such as C#, VB.NET, are guaranteed to be...
|
by: Olumide |
last post by:
Hi -
I've got a class that contains static member functions alone, all of
whose arguments are passed by reference as shown below:
class MySpiffyClass{
// no constructor, destructor or variables, just static members
static void FirstFunction( args & );
static void SecondFunction( args & );
static void ThirdFunction( args & );
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |