
I want to bring to your attention a series of articles on the Microsoft Workflow Foundation. This technology represents a new, higher level of abstraction in programming under .net. We begin with an introductory article that describes the background to the emergence of technology, two main types of workflows and development tools. In the future, we will learn more about the various aspects of the Microsoft Workflow Foundation.
Interested - read on.
Introduction
If you look back, the world around us is an endless series of processes that replace each other. We plant grain, it germinates, blooms, leaves offspring, dies. In its place grows something new. And so day after day. People try to describe these processes, simulate them on a computer, invent something new. For this, various mental models are created that simplify the description of everyday processes. Levels of abstraction are introduced. For example, invented object-oriented programming. With it, you can describe the objects of the real world. It is easy and natural. It is enough to look at the thing and a more or less accurate model emerges in my head: what properties this object has, what actions can it perform.
But objects that do not interact with each other, have no meaning. Life is a movement, often cyclical. On the other hand, there is a man in the world. He brings some confusion with his intelligence. Many things he does are inconsistent. Motives are not always clear. Timing does not always meet expectations. A person can forget about something, do something wrong, as he had conceived before. And at the same time, he also operates on objects. Be it objects of the real world, such as stones, flowers, water, or the virtual: documents, information, words.
')
It is to describe the movement and interaction of objects within programs created technology Microsoft Workflow Foundation. This is a link that allows you to create interactions that connect objects with each other or processes that take place inside the objects themselves. The Workflow Foundation (WF) divides all processes into two basic types: sequential processes (sequential processes) and processes based on states (state machine).
Sequential processes

Sequential processes, in the understanding of WF, are those processes that usually occur without external intervention. Also, they take relatively little time. A good example of such a process is the copying of files from one folder to another: we set the folders at the beginning of the process, and then do not intervene in it until completion. Those. This, in fact, debugged conveyor. Yes, something can break and require some action, but these are exceptional situations that are handled separately.
State Based Processes

The best example of a state-based process is in its translation. State machine literally means state apparatus. This is a process that has many states that, depending on various events, can move from one to another. We usually see all this in the bureaucratic apparatus: state insurance, sale of an apartment, etc. Signatures are required by various officials who may be on vacation or on sick leave. Such a process can take a very long time: days, weeks, or even months. For such situations the state-machine workflow is created.
What WF gives us
Let's now see what the WF gives us. First of all, this is visibility. All of us are constantly drawing some kind of schematics, sketches. In more complex cases, we delve deeper into the design, for example, draw time diagrams. Now we can transfer these sketches to Microsoft Visual Stuidio 2008 using the built-in editor. Here's what it looks like:

Even a person who is far from programming can figure out what is happening on the diagram.
But all these sketches are divorced from the current program, they do not interact with it in any way. If we need to change the course of the process, then we need to open the sources, remember the places where you need to make changes according to the new sketch. These tasks allows you to solve the WF. We can simply take and move the code section to another place. Immediately compile it and compare it with the original version.
Also the use of WF helps to more visually present the work of the system. Select processes that can be divided into components or vice versa, combined. Transactional systems are also supported: you can specify a compensating process for the case when something went wrong. This process will return the system to the state it was in before the error occurred.
It is possible to publish the process as a service or web service accessible via the Internet. Moreover, you can create a so-called Durable web-service, which saves the session identifier and the state of the service in between calls, allowing you to run the process for a long time without maintaining the connection. You can even stop the process, save the status and run it on another computer from the same place.
Development tools
The most convenient development tool is the visual editor built into Visual Studio 2008. It allows you to quickly and flexibly create and modify processes. There is no need to understand how it works on a low level. You can also create processes using XAML markup language or using C #.
Let's take a look at the basic interface elements for working with processes in a studio. Here is the window in the development process:

Consider the purpose of each panel.

This is the main document in which we model the process. Now we see an invitation to drag there some elements to create a consistent process.

The process consists of basic elements called Activity. They are number two on the Toolbox. It contains many elements. Some of them are quite understandable by their name. For example, While or IfElse. ConditionedActivityGroup sounds more mysterious.

Naturally, you will need the Properties panel to configure all sorts of parameters.

Also very useful is the Document Outline panel, indicated by the number four. It displays a tree of elements of this process, allowing you to quickly move from one element to another.
Conclusion
WF provides the developer with a higher level of abstraction when working on a project. Allows you to try new ideas, using existing developments. You can create a library of frequently used processes and their elements for reuse in other projects. In the next article we will take a closer look at sequential processes using the example of a program that backs up files.