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

Outlook : "operation failed, object could not be found. " when trying to close a PST.

How to transfer app and data from old iPhone to new iPhone for model IOS17 and IOS18 above.

Tips on how to use IBM iNotes (web client) on emailing or scheduling - Like copy tables from Excel or checking for user id (windows logon id) through email address