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 或工作流程執行階段引擎根據本身語意的隱含呼叫,可從記憶體中卸載工作流程執行個體。 例如,如果實例變成閒置狀態,且執行時間已加入 , WorkflowPersistenceService 則工作流程執行時間引擎會卸載工作流程實例,其 UnloadOnIdletrue 為 。

工作流程執行時間引擎會在工作流程實例的狀態成功保存之後,但在實例在記憶體中失效之前引發 WorkflowUnloaded 事件。 因此,WorkflowPersisted 事件會發生在 WorkflowUnloaded 事件之前。

對於 WorkflowUnloaded 事件,傳送者會包含 WorkflowRuntime,而 WorkflowEventArgs 則包含事件關聯的 WorkflowInstance

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於