WorkflowApplication.Unload Method

Definition

Persists and unloads a workflow instance.

Overloads

Unload(TimeSpan)

Persists and unloads a workflow instance using the specified time-out interval.

Unload()

Persists and unloads a workflow instance.

Remarks

By default, the unload operation must complete in 30 seconds or a TimeoutException is thrown.

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

Unload(TimeSpan)

Persists and unloads a workflow instance using the specified time-out interval.

public:
 void Unload(TimeSpan timeout);
public void Unload (TimeSpan timeout);
member this.Unload : TimeSpan -> unit
Public Sub Unload (timeout As TimeSpan)

Parameters

timeout
TimeSpan

The interval in which the unload operation must complete before the operation is canceled and a TimeoutException is thrown.

Examples

In this example, the workflow is idle and the host application is waiting for user input. If the user chooses to unload, Unload is called. If successful, the workflow is persisted and unloaded from memory.

// single interaction with the user. The user enters a string in the console and that
// string is used to resume the ReadLine activity bookmark
static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
{
    Console.WriteLine("Workflow is ready for input");
    Console.WriteLine("Special commands: 'unload', 'exit'");

    bool done = false;
    while (!done)
    {
        Console.Write("> ");
        string s = Console.ReadLine();
        if (s.Equals("unload"))
        {
            try
            {
                // attempt to unload will fail if the workflow is idle within a NoPersistZone
                application.Unload(TimeSpan.FromSeconds(5));
                done = true;
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        else if (s.Equals("exit"))
        {
            application.ResumeBookmark("inputBookmark", s);
            done = true;
        }
        else
        {
            application.ResumeBookmark("inputBookmark", s);
        }
    }
    resetEvent.WaitOne();
}

Remarks

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

Applies to

Unload()

Persists and unloads a workflow instance.

public:
 void Unload();
public void Unload ();
member this.Unload : unit -> unit
Public Sub Unload ()

Examples

In this example, the workflow is idle and the host application is waiting for user input. If the user chooses to unload, Unload is called. If successful, the workflow is persisted and unloaded from memory.

// single interaction with the user. The user enters a string in the console and that
// string is used to resume the ReadLine activity bookmark
static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
{
    Console.WriteLine("Workflow is ready for input");
    Console.WriteLine("Special commands: 'unload', 'exit'");

    bool done = false;
    while (!done)
    {
        Console.Write("> ");
        string s = Console.ReadLine();
        if (s.Equals("unload"))
        {
            try
            {
                // attempt to unload will fail if the workflow is idle within a NoPersistZone
                application.Unload(TimeSpan.FromSeconds(5));
                done = true;
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        else if (s.Equals("exit"))
        {
            application.ResumeBookmark("inputBookmark", s);
            done = true;
        }
        else
        {
            application.ResumeBookmark("inputBookmark", s);
        }
    }
    resetEvent.WaitOne();
}

Remarks

By default, the unload operation must complete in 30 seconds or a TimeoutException is thrown.

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

Applies to