WorkFlow
Windows Workflow Foundation
Posted on
Wednesday, February 04, 2009 12:49 PM
Source Code:MSDN
In previous versions, application used to get reference to Current workflowrutime by using codes like this:
WorkflowRuntime workflowRuntime=WorkflowRequest.Current.WorkflowRuntime;
But with 3.5 web applications use application object to store the workflowRuntime when the application starts and disposes of the runtime instance when the application stops. Global.asax file is used to hook the application_start and Application_End Event.
Here is how it is done:
void Application_Start(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime =
new System.Workflow.Runtime.WorkflowRuntime();
System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService manualService =
new System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService();
workflowRuntime.AddService(manualService);
workflowRuntime.StartRuntime();
Application["WorkflowRuntime"] = workflowRuntime;
}
void Application_End(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime =
Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
workflowRuntime.StopRuntime();
}
This workFlowRuntime instance remains in the application object as long as the webapplication handles requests.
Here is how you can how to retrieve this workflow runtime instance from the application object and star a workflow successfully.
protected void StartRuntime_Click(object sender, EventArgs e)
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;
ManualWorkflowSchedulerService manualScheduler =
workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService))
as ManualWorkflowSchedulerService;
WorkflowInstance instance = workflowRuntime.CreateWorkflow(
typeof(ASPNetSequentialWorkflow));
instance.Start();
manualScheduler.RunWorkflow(instance.InstanceId);
}
Posted on
Tuesday, February 03, 2009 12:59 PM
Source: MSDN
Things you should know before working on Workflow.
*** A workflow built on Windows Workflow Foundation is a component that requires an ad hoc runtime environment to function. The workflow runtime environment is represented by the WorkflowRuntime class. To host a workflow library, you create and configure an instance of the WorkflowRuntime class to operate on a particular workflow type. For performance reasons, you normally create the runtime environment only once in the application lifetime and make it serve all incoming requests. In a Windows Forms application, you initialize the workflow runtime in the form's constructor and destroy it with the form when the application shuts down.