Learn Windows Workflow Foundation with me (1) -- create and debug a WF instance

Source: Internet
Author: User

Today, I plan to start learning about WWF. I found some related documents and experiments on the Internet. However, the materials are mostly in English, so it seems hard to learn, but I believe I can stick to it and improve my English Reading Ability by the way, but my English level is really poor, please forgive me for not explaining anything or wrong (never laugh at me, haha ). After all, I started to learn about WWF from the blank space. Let's make progress together.

First, install WinFX (download) and Visual Studio 2005 extensions for. NET Framework 3.0 (Windows Workflow Foundation ). This is a necessary development component.

These examples and tutorials are downloaded from Microsoft labs and are divided into 10 parts. First to learn the most basic part first :)

Purpose of the First Part

This experiment aims to introduce the key points of the Workflow concept of Windows Workflow Foundation.

After completing this experiment, we can learn:

· Use Visual Studio 2005 to design a sequential workflow for WWF

· Configure and use the Visual Studio 2005 debugger to debug your workflow

· Allow the workflow to accept parameters

· Trigger a new workflow instance by receiving events

· Define conditions

· Configure basic activities for If/Else, Delay, Listen, and Code (activities do not know how to translate)

· Customizes activities for the events received by the Workflow

A workflow is defined in an activity diagram. It may be a human operation or a system process. An activity is a step in a workflow. It is embodied as an executable unit that can be reused and integrated. After the workflow is designed, it is compiled into a. net assembly and executed by the workflow runtime and the general language runtime (CLR.

 

1. CreateHello WorldWorkflow

In this exercise, we will use the VS2005 workflow designer to design a very simple "Hello World" workflow. The Hello World workflow implements an ordered workflow through simple code. It outputs "Hello, World!" in our command line !". We will understand the definition and code of a workflow. Finally, we will learn how to use VS2005 to execute and debug our workflows on our machines.

Open VS 2005, create a project, select "ordered workflow console application", and change the project name to HelloWorldWorkflow.

 

1. Click "OK" to generate a new workflow project.

2. This project will automatically generate a workflow template Workflow1 for us. Here we do not need this template. we just make a very simple example, So we delete this Workflow1.cs file.

3. Right-click the project and choose add new project.

4. Select "sequential workflow (with separate code)" and click "OK" to add the workflow. Here, two files Workflow1.xoml and Workflow1.xoml. cs will be added. Workflow1.xoml contains the XML language that describes the workflow type, and the file with its CS suffix contains the action Execution Code in the workflow.

5. Now we have to add code. Double-click the Workflow1.xoml file to open the view of the VS workflow designer.

6. We can perform various activities from the toolbox that we can add.

7. Drag the "Code" activity from the toolbox to our workflow.

8. note: At this time, there is a red exclamation point in the upper right corner of the "Code" activity we drag in. Click the drop-down triangle and we can see this exclamation point, this is because the ExecuteCode attribute has not been set.

9. The next step is very clear. We need to set ExecuteCode. Click this prompt and we will send it toExecuteCodeHighlighted.CodeactivityappscodehandlerAnd double-click.Workflow1.xoml. csCodeactivityjavascodehandler method generated in

10. As you can see, this class inherits fromSequentialWorkflowActivityBase class. We need to enter the following in the method:

Console. WriteLine ("Hello, World! ");

The Code is as follows:

Using System;
Using System. ComponentModel;
Using System. ComponentModel. Design;
Using System. Collections;
Using System. Drawing;
Using System. Workflow. ComponentModel. Compiler;
Using System. Workflow. ComponentModel. Serialization;
Using System. Workflow. ComponentModel;
Using System. Workflow. ComponentModel. Design;
Using System. Workflow. Runtime;
Using System. Workflow. Activities;
Using System. Workflow. Activities. Rules;
Namespace HelloWorldWorkflow
{
Public partial class Workflow1: SequentialWorkflowActivity
{
Private void codeactivityinclucodehandler (object sender, EventArgs e)
{
Console. WriteLine ("Hello, World! ");
}
}
}

 

11. Press Ctrl + F5 to run the program. If:
The operation is successful.

12. Is it too simple? At least, the first workflow is completed.

13. Wait. Don't worry. There is another interesting thing, that is, the WWF debugging function. We used to set breakpoints in the code during previous debugging. Now, you can try to debug WWF.

14. Open the design view Workflow1.xoml of the workflow.

15. Right-click codeActivity1, select breakpoint, and insert breakpoint (or click F9 after selection). What do you see?

6. Now press F5 and it will stop when the execution ends. You can debug it.

7. at, the single-step execution of F11 will go to our codeactivityappscodehandler event. Is it very convenient?

 

Let's talk about so much today and continue learning tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.