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