473,387 Members | 1,590 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,387 software developers and data experts.

threadin issues.

Hi All,
I am designing a class library that can be used by web and windows
client both, the problem is that i want to initiate certain behavior in
class that is thread specific, yet i want to declare a static methods
for this behavior....

doing some research online i found out that one can use Thread Local
Storage or mark a variable with ThreadStatic attribute, I also found
that both methods are not recommended for use with ASP.net applications
because same thread can be used serve multiple request, and threads come
from a pool ..

anyway other good way to accomplish it , keeping its applicability
transparent ?
TIA
-ashish
Nov 19 '05 #1
4 1119
it all depends on what your class is designed to do. If you are going to
share global variables you will need to protect them. otherwise you don't
need to worry about threading.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Ashish" <as*****@thisisjunk.com> wrote in message
news:##**************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am designing a class library that can be used by web and windows
client both, the problem is that i want to initiate certain behavior in
class that is thread specific, yet i want to declare a static methods
for this behavior....

doing some research online i found out that one can use Thread Local
Storage or mark a variable with ThreadStatic attribute, I also found
that both methods are not recommended for use with ASP.net applications
because same thread can be used serve multiple request, and threads come
from a pool ..

anyway other good way to accomplish it , keeping its applicability
transparent ?
TIA
-ashish

Nov 19 '05 #2
Ashish,

When developing a class library you normally make sure all static
members are thread-safe. Instance members are not typically
thread-safe because each thread can (and usually does) create its own
instance of that class that is not shared by other threads. If more
than one thread needs to share the same instance then it's the
responsibility of the callers to synchronization access to the instance
members. This is the general pattern Microsoft used in the base class
library.

I don't recommend using any thread specific techniques including Thread
Local Storage or the ThreadStatic attribute. What behavior is it that
you want to be thread specific?

Brian

Ashish wrote:
Hi All,
I am designing a class library that can be used by web and windows
client both, the problem is that i want to initiate certain behavior in
class that is thread specific, yet i want to declare a static methods
for this behavior....

doing some research online i found out that one can use Thread Local
Storage or mark a variable with ThreadStatic attribute, I also found
that both methods are not recommended for use with ASP.net applications
because same thread can be used serve multiple request, and threads come
from a pool ..

anyway other good way to accomplish it , keeping its applicability
transparent ?
TIA
-ashish


Nov 19 '05 #3

I have implemented a DataBase Manager, that saves all the objects
registered with it.

So the client can just register all the objects it wants to save,Delete
with this Manager, and then flushes the manager (much like a O/R Session)

I would like to create a transaction object and add it to the call
context or current thread, then all the database operations can check
whether there is a transaction object in the call context, this would
save me from passing the transaction object reference around, and make
the code much cleaner.

I can use [ThreadStatic] attribute, but threads gets reused, on another
note Is a thread dedicated to the whole life time of a request ?

anyways any pointers would be appreciated.

TIA
-ashish




Brian Gideon wrote:
Ashish,

When developing a class library you normally make sure all static
members are thread-safe. Instance members are not typically
thread-safe because each thread can (and usually does) create its own
instance of that class that is not shared by other threads. If more
than one thread needs to share the same instance then it's the
responsibility of the callers to synchronization access to the instance
members. This is the general pattern Microsoft used in the base class
library.

I don't recommend using any thread specific techniques including Thread
Local Storage or the ThreadStatic attribute. What behavior is it that
you want to be thread specific?

Brian

Ashish wrote:
Hi All,
I am designing a class library that can be used by web and windows
client both, the problem is that i want to initiate certain behavior in
class that is thread specific, yet i want to declare a static methods
for this behavior....

doing some research online i found out that one can use Thread Local
Storage or mark a variable with ThreadStatic attribute, I also found
that both methods are not recommended for use with ASP.net applications
because same thread can be used serve multiple request, and threads come
from a pool ..

anyway other good way to accomplish it , keeping its applicability
transparent ?
TIA
-ashish


Nov 19 '05 #4
Ashish wrote:
I have implemented a DataBase Manager, that saves all the objects
registered with it.

So the client can just register all the objects it wants to save,Delete
with this Manager, and then flushes the manager (much like a O/R Session)

I would like to create a transaction object and add it to the call
context or current thread, then all the database operations can check
whether there is a transaction object in the call context, this would
save me from passing the transaction object reference around, and make
the code much cleaner.

Honestly, passing around a transaction reference would be a better
approach. Since you say you have a database manager object then
couldn't you encapsulate the transaction handling there? That way you
wouldn't have to keep passing around the reference.
I can use [ThreadStatic] attribute, but threads gets reused, on another
note Is a thread dedicated to the whole life time of a request ?

I'd say it's likely that a request is serviced by a single thread, but
I can't tell you that for sure.
anyways any pointers would be appreciated.

TIA
-ashish


Nov 19 '05 #5

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

Similar topics

2
by: Tom Loredo | last post by:
Hi folks- I'm about to move from a Solaris 8/SPARC environment to a Dell running RedHat 9. Are there any issues I need to be aware of in bringing my Python code over (mostly scientific...
28
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
5
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
1
by: Aliandro | last post by:
Hi Does any one know where I can find information regarding any issues with SQL and IIS being run under windows XP SP2? as I am in the process of programmning in Dot net and neet some way of...
7
by: David Laub | last post by:
I have stumbled across various Netscape issues, none of which appear to be solvable by tweaking the clientTarget or targetSchema properties. At this point, I'm not even interested in "solving"...
2
by: G2 | last post by:
Hi We are dealing with significant browser compatibility issues with Netscape 5.x+ browsers and Mac IE. I am sure most web developers have faced similar issues in the past. Can anyone give me their...
1
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
3
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.