Datasheet
Chapter 1: Workfl ow Programming Principles
4
Clearly, the execution model of an activity or logical program statement is fundamentally different from
that of a C# program statement. A C# program statement does not suspend its execution and resume it
later on a different thread, process, or machine. A C# program statement cannot be resumed. That is why
when a C# program crashes, you have to rerun the program. When a C# program is rerun, it does not
resume its execution from the last program statement that was executing. That ’ s because a C# program
relies on the thread on which it is running to maintain its execution context. This execution context is
gone when the thread is gone.
A business activity or logical program statement must be resumable. As such, a business process or
workflow or logical program must not rely on the thread on which it is running to maintain its execution
context. Instead, it must explicitly allocate memory for its execution context on the heap so it can
serialize its execution context into a durable storage such as a database when it suspends its execution
and waits indefinitely for an external entity to deposit data. This enables the logical program to
deserialize its execution context from the durable storage and resume its execution where it left off when
the external data finally arrives.
Now you can see the type of challenges you face when you ’ re implementing a workflow or logical
program. If you were to handle all these challenges on your own, you would end up writing a
tremendous amount of infrastructural code that has nothing to do with the specifics of your application
requirements. This is where Windows Workflow Foundation (WF) comes into play. WF provides you
with a comprehensive workflow programming framework that enables you to implement workflows or
logical programs with minimal time and effort.
Custom Activities
A traditional procedural program such as a C# program is a hierarchy, or tree, of program statements.
For example, consider the following C# program:
public class Program
{
public static void Main (string[] args)
{
bool bcontinue = bool.Parse(Console.ReadLine());
while (bcontinue)
{
if (args[0] == “String1”)
Console.WriteLine(“String one was entered”);
else
Console.WriteLine(“String one was not entered”);
bcontinue = bool.Parse(Console.ReadLine());
}
}
}
Figure 1 - 1 presents the program statement hierarchy, or tree, for this C# program.
c01.indd 4c01.indd 4 8/25/08 4:02:52 PM8/25/08 4:02:52 PM