ThreadPool & Object lifetime
In an asp.net web application, there is a thread pool which is used to call a method.
This method, uses an instance of EF ObjectContext to perform its operation.
I am using Unity Framework which resolves an ObjectContext using the per-thread-lifetime manager.
Does this guarantee that at the end of the method operation, the thread will be returned to the Thread开发者_JS百科Pool & the ObjectContext will be disposed?
Any thoughts or articles on how the lifetime of the objects on a ThreadPool is managed will be really useful.
Thanks a million!
If you want to be sure the context is disposed, just do it in the method:
private void Foo()
{
using (var context = new MyEntities())
{
DoStuff(context);
}
}
The context is a unit of work. It's appropriate to create and free it in this case.
精彩评论