After completing this chapter, you will learn:
1. Know how to use sequence activities
2. Know how to use code activities
3. Know how to throw an exception and process it in a workflow
4. Know how to pause and terminate your workflow instance in code
In this chapter, we will formally introduce a set of activities that we have seen before: sequence activities and code activities. But I believe that proper error handling is critical to well-designed and well-run software, so we'll look at how to use activities in a workflow to throw exceptions, catch exceptions, or even pause and terminate your workflow. Let's start with the sequence activity.
Using Sequential active objects
In fact, it is not entirely true that we have seen sequence activities. When we create a workflow application, we actually use the sequentialworkflow activity, but the general meaning is the same: This activity contains other activities that are to be executed sequentially. This can be compared to the parallel execution using the parallel activity, and we will see the parallel activity in chapter 11th ("Parallel activity").
When you perform a task in a particular order, you must complete the tasks in turn, which is usually necessary.
The sequence activity is a composite activity that we have discussed briefly in chapter fourth ("Introduction to activities and Workflow types"). It contains other activities that must be performed in sequence. You can include other combinations of activities, including parallel activities, within the parent sequence activity. However, the child activities are executed sequentially, one after the other, even if the parallel execution flows contained in the child activities themselves.
Let's use the sequence activity to create a simple workflow. We'll use the code activity again, and the more detailed details about it will be discussed in the next section, "Using code activities." To understand the behavior of a particular workflow activity, we will go back to the console based application. For a console-based application, you usually need to write less code because you don't have to process the user interface. (But as the book progresses, we'll create other graphical test cases as well.) )
Create a workflow that uses the sequence activity
1. Download the source code in this chapter, the final version of this example is available in the "Sequencer Completed" directory, which you can use Visual Studio 2008 to open and view its running results directly. The "Sequencer" directory is the practice version, and we'll start with this example, starting with Visual Studio 2008 to open the solution.
2. Add a sequential Workflow library project to our solution with the project name "Sequencerflow".
3. Drag a sequence activity from the toolbox to Visual Studio's Workflow View Designer.