TechTalk Genome v4.2

Context.Pop Method 

Unloads the active Context in the calling thread and sets the previously active context (that is on the top of the thread's context stack) to be the active context.

public static IContext Pop();

Return Value

The active context that is unloaded from the calling thread.

Remarks

The Pop method unloads the active Context in the calling thread and restores the threads data access configuration to the same state as before the last call to Push.

If the Pop method is called to unload a Context from the context stack of the calling thread, the context stack cleaner object returned from the Push method call that was used to load the concerned context should be discarded and must not be disposed neither by calling its IDisposable.Dispose method nor by using the return value in a using statement. If both the Pop method and the context stack cleaner are used a context missalignment will occur.

As the Pop method provides no means of automatic context nesting verification, it is strongly recommended that automatic context stack management provided by context stack cleaner objects is used whenever it is possible. Manual context management should only be used in scenarios where using directives are not possible, such as request lifetime context scenarios in ASP.NET applications.

Exceptions

Exception TypeCondition
GenomeException

The calling thread does not have an active Context.

Example

Context myContext = ShortRunningTransactionContext.Create();
try 
{
    Context.Push(myContext);

    foreach (Employee e in dataDomain.Extent(typeof(Employee)) 
    {
        e.Age++;
        Console.WriteLine(e.Age);
    }
}
finally
{
    // remove the context from the context stack and dispose it
    // to ensure that the underlying database connection is closed
    Context.Pop(myContext);
    myContext.Dispose();
}

// The following code uses the context stack cleaner returned by the
// Push method. This code behaves the same as the try-finally above.
using (Context.Push(ShortRunningTransactionContext.Create()))
{
    foreach (Employee e in dataDomain.Extent(typeof(Employee)) 
    {
        e.Age++;
        Console.WriteLine(e.Age);
    }
    // the context stack cleaner removes and disposes the context at the end of the using block
}
                

Requirements

Namespace: TechTalk.Genome

Assembly: TechTalk.Genome (in TechTalk.Genome.dll)

Version: 4.2.11.59

Editions: Professional, Evaluation, Express

See Also

Context Class | TechTalk.Genome Namespace | Push | Current | CtxMgmtGuide.Chapter3