Host Workflow in .NET WinForm

Add reference to
- System.Workflow.Activities
- System.Workflow.Runtime
- System.Workflow.ComponentModel
- <the MyWorkflow assembly>

in the WinForm codes,

add member variable

WorkflowRuntime myWorkflowRuntime = new WorkflowRuntime()

Then, in the constructor of the winform.
//setup event handler
myWorkflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArg>(wr_WFCompleted);
myWorkflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArg>(wr_WFTerminated);


//handler for the workflow thread.
void wr_WFCompleted(object sender, WorkflowCompletedEventArg e)
{
MessageBox.Show("Workflow output" + e.OutputParameters["Field"].ToString());
}


//to kick start the work flow thread.
Type type = typeof(MyNamespace.MyWorkflow);
//to pass parameter to the workflow thread.
Dictionary<string, object> param = Dictionary<string, object>;
param.Add("Field", System.Convert.ToInt32(123));
WorkflowInstance myWI= myWorkflowRuntime.CreateWorkflow(type, param);
myWI.Start();

Comments

Popular posts from this blog

Clearcase check in/uncheck out all the checked out files script

MSSQL GROUP_CONCAT

Duplicating a local copy of project from TFS and making web software client factory to work