WorkflowRuntime.WorkflowUnloaded イベント

定義

ワークフロー インスタンスがメモリからアンロードされると発生します。

public:
 event EventHandler<System::Workflow::Runtime::WorkflowEventArgs ^> ^ WorkflowUnloaded;
public event EventHandler<System.Workflow.Runtime.WorkflowEventArgs> WorkflowUnloaded;
member this.WorkflowUnloaded : EventHandler<System.Workflow.Runtime.WorkflowEventArgs> 
Public Custom Event WorkflowUnloaded As EventHandler(Of WorkflowEventArgs) 
Public Event WorkflowUnloaded As EventHandler(Of WorkflowEventArgs) 

イベントの種類

次のコード例は、ワークフローのホストから WorkflowRuntime の機能を使用する方法を示しています。 このコードでは、WorkflowUnloaded をイベント ハンドラーである OnWorkflowUnload という名前のメソッドに関連付けています。

このコード例は、 カスタム永続化サービス サンプルの一部です。

static void Main()
{
    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
        try
        {
            // engine will unload workflow instance when it is idle
            workflowRuntime.AddService(new FilePersistenceService(true));

            workflowRuntime.WorkflowCreated += OnWorkflowCreated;
            workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
            workflowRuntime.WorkflowIdled += OnWorkflowIdle;
            workflowRuntime.WorkflowUnloaded += OnWorkflowUnload;
            workflowRuntime.WorkflowLoaded += OnWorkflowLoad;
            workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
            workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

            workflowRuntime.CreateWorkflow(typeof(PersistenceServiceWorkflow)).Start();

            waitHandle.WaitOne();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
        }
        finally
        {
            workflowRuntime.StopRuntime();
            Console.WriteLine("Workflow runtime stopped, program exiting... \n");
        }
    }
}
Shared Sub Main()

    Using currentWorkflowRuntime As New WorkflowRuntime()
        Try

            ' engine will unload workflow instance when it is idle
            currentWorkflowRuntime.AddService(New FilePersistenceService(True))

            AddHandler currentWorkflowRuntime.WorkflowCreated, AddressOf OnWorkflowCreated
            AddHandler currentWorkflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
            AddHandler currentWorkflowRuntime.WorkflowIdled, AddressOf OnWorkflowIdled
            AddHandler currentWorkflowRuntime.WorkflowUnloaded, AddressOf OnWorkflowUnloaded
            AddHandler currentWorkflowRuntime.WorkflowLoaded, AddressOf OnWorkflowLoaded
            AddHandler currentWorkflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated
            AddHandler currentWorkflowRuntime.ServicesExceptionNotHandled, AddressOf OnExceptionNotHandled

            currentWorkflowRuntime.CreateWorkflow(GetType(PersistenceServiceWorkflow)).Start()

            waitHandle.WaitOne()

        Catch e As Exception
            Console.WriteLine("Exception \n\t Source: 0} \n\t Message: 1}", e.Source, e.Message)
        Finally
            currentWorkflowRuntime.StopRuntime()
            Console.WriteLine("Workflow runtime stopped, program exiting... \n")
        End Try
    End Using
End Sub

注釈

ワークフロー インスタンスは、Unload の明示的呼び出し、またはワークフロー ランタイム エンジンによる自身のセマンティクスに基づく暗黙的な操作によって、メモリからアンロードされます。 たとえば、インスタンスがアイドル状態になり、ランタイムに が 追加UnloadOnIdletrueされている場合、ワークフロー ランタイム エンジンはWorkflowPersistenceServiceワークフロー インスタンスをアンロードします。

ワークフロー ランタイム エンジンは、ワークフロー インスタンスの WorkflowUnloaded 状態が正常に永続化された後、インスタンスがメモリ内で無効になるまでにイベントを発生させます。 したがって、WorkflowPersisted イベントが WorkflowUnloaded イベントより前に発生することになります。

WorkflowUnloaded イベントでは、送信元に WorkflowRuntime が含まれ、WorkflowEventArgs にはイベントに関連付けられている WorkflowInstance が格納されます。

イベントの処理の詳細については、「イベントの 処理と発生」を参照してください。

適用対象