views:

45

answers:

1

Hi,

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 ThreadPool & 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!

A: 

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.

Craig Stuntz