473,385 Members | 1,409 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.

ASP.NET, threading and static member.

Hi all,

Each time an HTTP request is received by IIS, it forwards it to the ASP.NET
worker process. Then does the ASP.NET worker process in turn start a new
thread for each HTTP request it serves (from a pool of thread for example).
Or are all HTTP requests served by the same thread?

An other question is related to static members. A static member in a class
will have the same value across all its instance. But for example if 2
instances of the class are in 2 different threads, will the static member
still share the value or not? If I remember well, in Java, static member do
not share the same value between different threads and I would like to know
if it is the same thing in C# or not.

If anyone got a good link explaining one of both of the 2 topics above that
would be great too !

Thanks in advance,

Francois
Nov 19 '05 #1
8 1319
Francois <fr******@bettinghouses.com_NOSPAM> wrote:
Each time an HTTP request is received by IIS, it forwards it to the ASP.NET
worker process. Then does the ASP.NET worker process in turn start a new
thread for each HTTP request it serves (from a pool of thread for example).
Or are all HTTP requests served by the same thread?
I believe they're served by the thread-pool.
An other question is related to static members. A static member in a class
will have the same value across all its instance.
It's not that it's shared across all instances - it's that the member
belongs to the type rather than to any instance.
But for example if 2
instances of the class are in 2 different threads, will the static member
still share the value or not? If I remember well, in Java, static member do
not share the same value between different threads and I would like to know
if it is the same thing in C# or not.


It's the same in C# as in Java, but you remember Java incorrectly.
Static members are shared across threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #2
Tx a lot Jon,

Do you know if there is there any way to set some sort of a type value that
will be limited to the scope of a thread only? or is that impossible to do?

Tx in advance and tx again for your answer.

Francois
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Francois <fr******@bettinghouses.com_NOSPAM> wrote:
Each time an HTTP request is received by IIS, it forwards it to the ASP.NET worker process. Then does the ASP.NET worker process in turn start a new
thread for each HTTP request it serves (from a pool of thread for example). Or are all HTTP requests served by the same thread?


I believe they're served by the thread-pool.
An other question is related to static members. A static member in a class will have the same value across all its instance.


It's not that it's shared across all instances - it's that the member
belongs to the type rather than to any instance.
But for example if 2
instances of the class are in 2 different threads, will the static member still share the value or not? If I remember well, in Java, static member do not share the same value between different threads and I would like to know if it is the same thing in C# or not.


It's the same in C# as in Java, but you remember Java incorrectly.
Static members are shared across threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 19 '05 #3
You can keep thread specific data by using SetData and GetData static
methods. to give the appearance that it's part of the type, you can use a
property to wrap that logic.

"Francois" wrote:
Tx a lot Jon,

Do you know if there is there any way to set some sort of a type value that
will be limited to the scope of a thread only? or is that impossible to do?

Tx in advance and tx again for your answer.

Francois
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Francois <fr******@bettinghouses.com_NOSPAM> wrote:
Each time an HTTP request is received by IIS, it forwards it to the ASP.NET worker process. Then does the ASP.NET worker process in turn start a new
thread for each HTTP request it serves (from a pool of thread for example). Or are all HTTP requests served by the same thread?


I believe they're served by the thread-pool.
An other question is related to static members. A static member in a class will have the same value across all its instance.


It's not that it's shared across all instances - it's that the member
belongs to the type rather than to any instance.
But for example if 2
instances of the class are in 2 different threads, will the static member still share the value or not? If I remember well, in Java, static member do not share the same value between different threads and I would like to know if it is the same thing in C# or not.


It's the same in C# as in Java, but you remember Java incorrectly.
Static members are shared across threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 19 '05 #4
Hi Francois:

I'm not sure what you ultimately want to accomplish, but in ASP.NET
you generally want a value around that is tied to a specific request,
not a specific thread. To do this you can use the Context.Items
collection.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 20 Dec 2004 18:29:25 +0700, "Francois"
<fr******@bettinghouses.com_NOSPAM> wrote:
Tx a lot Jon,

Do you know if there is there any way to set some sort of a type value that
will be limited to the scope of a thread only? or is that impossible to do?

Tx in advance and tx again for your answer.

Francois
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft. com...
Francois <fr******@bettinghouses.com_NOSPAM> wrote:
> Each time an HTTP request is received by IIS, it forwards it to theASP.NET > worker process. Then does the ASP.NET worker process in turn start a new
> thread for each HTTP request it serves (from a pool of thread forexample). > Or are all HTTP requests served by the same thread?


I believe they're served by the thread-pool.
> An other question is related to static members. A static member in aclass > will have the same value across all its instance.


It's not that it's shared across all instances - it's that the member
belongs to the type rather than to any instance.
> But for example if 2
> instances of the class are in 2 different threads, will the staticmember > still share the value or not? If I remember well, in Java, static memberdo > not share the same value between different threads and I would like toknow > if it is the same thing in C# or not.


It's the same in C# as in Java, but you remember Java incorrectly.
Static members are shared across threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 19 '05 #5
Daniel Jin <Da*******@discussions.microsoft.com> wrote:
You can keep thread specific data by using SetData and GetData static
methods. to give the appearance that it's part of the type, you can use a
property to wrap that logic.


Alternatively, use the [ThreadStatic] attribute
(ThreadStaticAttribute). It's only available on static variables
(AFAICT), but it keeps one variable per thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #6
Learning something new every day, thanks Jon!

"Jon Skeet [C# MVP]" wrote:
Daniel Jin <Da*******@discussions.microsoft.com> wrote:
You can keep thread specific data by using SetData and GetData static
methods. to give the appearance that it's part of the type, you can use a
property to wrap that logic.


Alternatively, use the [ThreadStatic] attribute
(ThreadStaticAttribute). It's only available on static variables
(AFAICT), but it keeps one variable per thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 19 '05 #7
asp.net not only uses a thread pool, but may switch threads during request
processing (thread agile). this makes thread local storage unreliable.

in .net, static data is shared across all thread (unless the ThreadStatic
attribute is used, which then uses TLS). due to aps.net thread agility
mentioned above, you can not use this method.

-- bruce (sqlwork.com)

"Francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
| Hi all,
|
| Each time an HTTP request is received by IIS, it forwards it to the
ASP.NET
| worker process. Then does the ASP.NET worker process in turn start a new
| thread for each HTTP request it serves (from a pool of thread for
example).
| Or are all HTTP requests served by the same thread?
|
| An other question is related to static members. A static member in a class
| will have the same value across all its instance. But for example if 2
| instances of the class are in 2 different threads, will the static member
| still share the value or not? If I remember well, in Java, static member
do
| not share the same value between different threads and I would like to
know
| if it is the same thing in C# or not.
|
| If anyone got a good link explaining one of both of the 2 topics above
that
| would be great too !
|
| Thanks in advance,
|
| Francois
|
|
Nov 19 '05 #8
Thanks to all for all your information. :)

Best regards,

Francois.

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
asp.net not only uses a thread pool, but may switch threads during request
processing (thread agile). this makes thread local storage unreliable.

in .net, static data is shared across all thread (unless the ThreadStatic
attribute is used, which then uses TLS). due to aps.net thread agility
mentioned above, you can not use this method.

-- bruce (sqlwork.com)

"Francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
| Hi all,
|
| Each time an HTTP request is received by IIS, it forwards it to the
ASP.NET
| worker process. Then does the ASP.NET worker process in turn start a new
| thread for each HTTP request it serves (from a pool of thread for
example).
| Or are all HTTP requests served by the same thread?
|
| An other question is related to static members. A static member in a class | will have the same value across all its instance. But for example if 2
| instances of the class are in 2 different threads, will the static member | still share the value or not? If I remember well, in Java, static member
do
| not share the same value between different threads and I would like to
know
| if it is the same thing in C# or not.
|
| If anyone got a good link explaining one of both of the 2 topics above
that
| would be great too !
|
| Thanks in advance,
|
| Francois
|
|

Nov 19 '05 #9

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

Similar topics

3
by: Savagesmc | last post by:
Problem Background: I am working on a thin wrapper for the pthreads interface on linux, and have encountered frustrating behavior. The idea is to have a "PosixThread" class that any class can...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
8
by: Francois | last post by:
Hi all, Each time an HTTP request is received by IIS, it forwards it to the ASP.NET worker process. Then does the ASP.NET worker process in turn start a new thread for each HTTP request it...
2
by: Howard Swope | last post by:
Could someone help explain thread safety issues in the System.Collections classes? The documentation states:...
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
13
by: Bob | last post by:
My WinForms app runs on the single default thread, and uses a single SqlConnection object for all queries. I need to use one or more timers to periodically execute some of them. My own testing...
8
by: Lothar Behrens | last post by:
Hi, I am thinking about using classes to encapsulate threads for my application. My requirements are the following: The thread implementation sould not know what has to be implemented in...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
13
by: Alexander Gnauck | last post by:
Hello, while using async sockets I ran into a strange problem which occurs only on some machines. I wrote a small demo application which can be used to reproduce the problem. You can download it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...

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.