2

I'm using WorkflowFoundation 4.0 in WinForms application. When the user closes the form, the program doesn't exit because the workflow is running in background.

The workflow is created like this:

WorkflowApplication workflow = new WorkflowApplication(new myActivity());
workflow.Run();

I'd like to 'close' it in my FormClosing event. Which method should I use? Terminate, Abort or Cancel?

veljkoz
  • 8,384
  • 8
  • 55
  • 91

2 Answers2

7

Depending on your needs/workflow either Terminate or Cancel. Abort is designed to leave the persisted state around, if you are using the instance store, and restart the workflow from the last saved state.

Use terminate if you want no more activities, including cleanup like Finally blocks, to execute. Use Cancel if you want to have the capability to have the workflow cleanup after itself. I would suggest Cancel in most cases.

Maurice
  • 27,582
  • 5
  • 49
  • 62
5

There is a thorough answer here:

Community
  • 1
  • 1
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221