WorkflowRuntime.WorkflowCreated 事件
定义
在创建工作流实例时发生。Occurs when a workflow instance is created.
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)
事件类型
示例
下面的代码示例演示如何使用工作流宿主中的 WorkflowRuntime 功能。The following code example demonstrates how to use WorkflowRuntime functionality from a workflow host. 该代码将 WorkflowCreated 与一个事件处理程序即一个名为 OnWorkflowCreated 的方法相关联。The code associates the WorkflowCreated with an event handler, a method named OnWorkflowCreated.
此代码示例是 自定义持久性服务示例的一部分。This code example is part of the Custom Persistence Service Sample.
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
注解
在完全构造工作流实例之后但在处理活动之前,工作流运行时引擎会引发 WorkflowCreated 事件。The workflow run-time engine raises the WorkflowCreated event after the workflow instance is completely constructed but before activities are processed. 在此事件中,发送方包含 WorkflowRuntime,而 WorkflowEventArgs 包含与事件关联的 WorkflowInstance。For this event, the sender contains the WorkflowRuntime and WorkflowEventArgs contains the WorkflowInstance associated with the event.
有关处理事件的详细信息,请参阅 处理和引发事件。For more information about handling events, see Handling and raising events.