Workflow learning notes (2)

Source: Internet
Author: User

The last time we introduced the definition of the work and its application scope, we had a preliminary understanding of the workflow. With the last basic knowledge, we can start learning the workflow!

First, let's introduce the development environment of the workflow. Of course, the development environment I'm talking about here is on the Microsoft platform (^-^ )! It should have been developed on the Microsoft platform .... well, to create our first workflow, We need to install and deploy our development environment. First, we need to install the following environment:

1. Microsoft Visual Studio 2005.

2. DOTNET framwork 3.0.

3. Visual Studio 2005 extensions for Windows Workflow Foundation (chs0000.exe

After installing the above three things, our development environment is deployed. Haha... we can finally develop the workflow. Isn't it so exciting! Speaking of other things, Microsoft's technical updates are too fast. 2.0 has not been fully understood yet, and 3.0 is coming again. I don't hear that vs2007 has been launched recently ....

Let's talk about the workflow mechanism first. Let's give an example first. Let's take a look at the example. Let's discuss the mechanism. I think this may be easier for everyone to understand.

Now let's start our workflow journey!

Step 1: Open Microsoft Visual Studio 2005 to create a project. We will see the interface shown in Figure 5. Then we will find that there is a Workflow under the Visual C # node.



We can see that the workflow provides six templates, but they are mainly divided into two categories: sequential workflow and state machine. Here we will not discuss what a sequence workflow is and what a state machine is. it should be because I think I have told you here, and you will not have a deep understanding. After we have a preliminary understanding, will it be very easy to look back at this question. (^-^) at least I think so.

Step 2: select a console program hellowordmyworkflow and click OK:

In our solution Resource Manager, we can see that vs2005 has automatically generated two for us. CS file. one of them is designed for use, and the other is where the main function is located, that is, the necessary file for workflow startup.

 

Now let's take a look at some of the built-in basic tools that Microsoft provides for us. Through these basic tool components, we can design a highly functional workflow. How can this be done !!

These controls are basic and are introduced everywhere on the Internet. I will not introduce them one by one first. Let's talk about them through examples.


Drag a code from the toolbar to our design area. Our interface has been deployed. Isn't it easy,

A careful friend may find out how the control has a red exclamation point in the upper right corner. If you are not busy, let's solve it and let it disappear ....

This exclamation mark is actually an indicator. He told us that the control must have a code segment bound to it. After we double-click it, a code segment will be automatically generated.

Private void codeactivityappsexecutecode_1 (Object sender, eventargs E)

{

}

Enter console. writeline ("Hello word"); so far, even if our workflow is finished, we are not busy. To see the effect, we need to add code in another place. double-click the program file and we will see the following code:

Using directives # region using directives

 

Using system;

Using system. Collections. Generic;

Using system. text;

Using system. Threading;

Using system. workflow. runtime;

Using system. workflow. runtime. Hosting;

 

# Endregion

 

Namespace hellowordmyworkflow

{

Class Program

{

Static void main (string [] ARGs)

{

Using (workflowruntime = new workflowruntime ())

{

Autoresetevent waithandle = new autoresetevent (false );

Workflowruntime. workflowcompleted + = delegate (Object sender, workflowcompletedeventargs e) {waithandle. Set ();};

Workflowruntime. workflowterminated + = delegate (Object sender, workflowterminatedeventargs E)

{

Console. writeline (E. Exception. Message );

Waithandle. Set ();

};

 

Workflowinstance instance = workflowruntime. createworkflow (typeof (hellowordmyworkflow. workflow1 ));

Instance. Start ();

 

Waithandle. waitone ();





}

}

}

}

Here is the core of our workflow. We can see the effect of our workflow by adding the following two lines of code to waithandle. waitone.

Console. writeline ("press any key to exit !! ");

Console. Readline ();

Click debug to run our workflow and you will see the following results:

So far, even if our first workflow is finished, how is it easy!

Here I just give a simple example to bring everyone into the workflow.

Well, write it here first!

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.