工作流(WF)生命周期事件

时间:2016-09-27 06:33:27

标签: .net workflow workflow-foundation-4 workflow-foundation persist

如果我在program.cs

中关注了“工作流程生命周期事件”

无法理解WaitOne()会等待哪个信号到达?

Completed具有最高优先级,或idle具有最高优先级或任何信号到达,它会收到吗?

app.Run();
syncEvent.WaitOne();



app.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    return PersistableIdleAction.Unload;   
};

app.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId);  
    syncEvent.Set();
};


app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);
    }
};

app.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

app.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    Console.WriteLine("Workflow {0} Idle.", e.InstanceId);
};

app.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);
    return UnhandledExceptionAction.Terminate;
};

1 个答案:

答案 0 :(得分:1)

你的"卸载"事件处理程序:

syncEvent.Set();

这将让等待继续。

事件不具有优先级,您可以按照它们发生的顺序获取它们。