Bagikan melalui


WorkflowRuntime.WorkflowUnloaded Kejadian

Definisi

Terjadi ketika instans alur kerja dibongkar dari memori.

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) 

Jenis Acara

Contoh

Contoh kode berikut menunjukkan cara menggunakan WorkflowRuntime fungsionalitas dari host alur kerja. Kode mengaitkan WorkflowUnloaded dengan penanganan aktivitas, metode bernama OnWorkflowUnload.

Contoh kode ini adalah bagian dari Sampel Layanan Persistensi Kustom.

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

Keterangan

Instans alur kerja dapat dibongkar dari memori dengan panggilan eksplisit ke Unload, atau secara implisit oleh mesin run-time alur kerja sesuai dengan semantiknya sendiri. Misalnya, mesin run-time alur kerja membongkar instans alur kerja jika instans menjadi menganggur dan runtime memiliki WorkflowPersistenceService yang ditambahkan yaitu UnloadOnIdletrue.

Mesin run-time alur kerja meningkatkan peristiwa setelah status instans WorkflowUnloaded alur kerja berhasil dipertahankan tetapi sebelum instans tidak valid dalam memori. Oleh karena itu, peristiwa WorkflowPersisted mendahului WorkflowUnloaded acara.

Untuk peristiwa tersebut WorkflowUnloaded , pengirim berisi WorkflowRuntime dan WorkflowEventArgs berisi yang WorkflowInstance terkait dengan peristiwa.

Untuk informasi selengkapnya tentang menangani peristiwa, lihat Menangani dan menaikkan peristiwa.

Berlaku untuk