Share via


WorkflowRuntime.ServicesExceptionNotHandled Kejadian

Definisi

Terjadi ketika layanan yang berasal dari WorkflowRuntimeService kelas memanggil RaiseServicesExceptionNotHandledEvent(Exception, Guid).

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

Jenis Acara

Contoh

Contoh kode berikut menunjukkan cara menggunakan WorkflowRuntime fungsionalitas dari host alur kerja. Kode ini terkait ServicesExceptionNotHandled dengan penanganan aktivitas, metode bernama OnExceptionNotHandled.

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

Layanan yang berasal dari WorkflowRuntimeService kelas dapat memanggil RaiseServicesExceptionNotHandledEvent metode untuk memberi tahu pelanggan tentang ServicesExceptionNotHandled peristiwa yang tidak dapat ditangani selama eksekusinya. Anda dapat berlangganan kejadian ini untuk menerapkan mekanisme pemulihan.

Kejadian ini dinaikkan ketika instans alur kerja belum dibuat oleh mesin run-time alur kerja dan pengecualian terjadi. Dalam skenario ini, satu-satunya cara untuk menginformasikan aplikasi host bahwa pengecualian terjadi adalah dengan menaikkan peristiwa ini. Namun, mesin run-time alur kerja tidak memanggil ini secara langsung. Sebaliknya, mesin run-time alur kerja memberikan pengecualian ke instans alur kerja atau, jika tidak ada instans, mengembalikan ke pemanggil, yang dalam hal ini sebenarnya adalah layanan yang mengaktifkan peristiwa ini. Jika Anda membuat layanan persistensi atau penjadwal Anda sendiri, Anda harus menerapkan peristiwa ini sendiri melalui metode dasar RaiseServicesExceptionNotHandledEvent .

Untuk peristiwa tersebut ServicesExceptionNotHandled , pengirim berisi WorkflowRuntime dan WorkflowEventArgs berisi Guid instans alur kerja yang menggunakan layanan dan Exception yang tidak dapat ditangani.

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

Berlaku untuk