.net - Can I create thread safe objects with ContextBoundObject? -
i have object serves multiple requests (threads) ... think of sqlconnection object across multiple threads ....
now, want create "thread" safe object aware of thread context in created.
so if thread1 creates object foo , thread2 tries access .... object foo ignore , "act" if thread1 running ...
will contextboundobject this? if yes, limitations?
pseudo code
public class foo { private int _threadid; public void dosomething() { (if thread.managedthreadid != _threadid) return; // thread safe stuff } }
behavior want achieve can made using synchronizationattribute.
however, using attribute serialize access members of class. on other hand if methods of class not require synchronization (like static method not share state) using synchronization attribute may result in degraded performance.
Comments
Post a Comment