WorkflowRuntime.WorkflowUnloaded 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从内存卸载工作流实例时发生。
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)
事件类型
示例
下面的代码示例演示如何使用工作流宿主中的 WorkflowRuntime 功能。 该代码将 WorkflowUnloaded 与一个事件处理程序即一个名为 OnWorkflowUnload
的方法相关联。
此代码示例是 自定义持久性服务示例的一部分。
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
注解
可以通过显式调用 Unload 从内存卸载工作流实例,也可以由工作流运行时引擎根据自身的语义来隐式卸载工作流实例。 例如,如果实例处于空闲状态,并且运行时添加了 WorkflowPersistenceService 为其 添加 UnloadOnIdle 的 , true
则工作流运行时引擎将卸载工作流实例。
工作流运行时引擎在 WorkflowUnloaded
工作流实例的状态成功持久化后,但在内存中实例失效之前引发事件。 因此,WorkflowPersisted 事件将在 WorkflowUnloaded 事件之前发生。
对于 WorkflowUnloaded
事件,发送方包含 WorkflowRuntime,而 WorkflowEventArgs 包含与事件关联的 WorkflowInstance。
有关处理事件的详细信息,请参阅 处理和引发事件。