1 Preface
There are many ways to control multi-threaded synchronization, such as the addition of synchronous locking mechanism, but this will bring some performance consumption, because to queue mechanism, the previous period of time to see someone else's code has a class (Threadlocal<t> generic Class) caught my attention.
2. Concept Threadlocal
View MSDN Explanation: to provide the thread local storage of data, in fact, it is easy to understand that a variable in multiple threads to implement multiple copies (copy), because the mechanism of multithreading, the variables of each thread are not affected, so do not worry about the variable caused by pollution, each use of the need not worry. Common variables for multiple threads can be implemented during database connection operations or ORM context operations.
Refer to the article: http://blog.csdn.net/sonny543/article/details/51336457
Solutions for controlling transactions in multithreading or concurrency