WorkflowRuntime.WorkflowCreated Evento

Definizione

Si verifica quando viene creata un'istanza del flusso di lavoro.

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

Tipo evento

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare una funzionalità WorkflowRuntime da un host del flusso di lavoro. Il codice associa WorkflowCreated a un gestore eventi, un metodo denominato OnWorkflowCreated.

Questo esempio di codice fa parte dell'esempio di servizio di persistenza personalizzata.

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

Commenti

Il motore di runtime del flusso di lavoro genera l'evento WorkflowCreated dopo che l'istanza del flusso di lavoro è stata completamente costruita ma prima che le attività vengano elaborate. Per questo evento, il mittente contiene WorkflowRuntime e WorkflowEventArgs contiene WorkflowInstance associata all'evento.

Per altre informazioni sulla gestione degli eventi, vedere Gestione e generazione di eventi.

Si applica a