Create and describe a simple workflow Program

Source: Internet
Author: User

This is the workflow entry.Program. After learning this workflow, you can bypass other workflows.

Create an ordered workflow console program helloworkflow. After the creation, the system generates the workflow1.cs file by default, which is a workflow file. Drag the code control in the toolbox on the workflow1 design page and enter codeactivityappsexecutecode in the executecode. Executecode indicates executionCode. For example.

 

Write the following code in the backend code of workflow1.cs. The purpose of this workflow is to display Hello workflow! On the console !.

Using System. collections;
Using System. drawing;
Using System. LINQ;
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 helloworkflow
{< br> Public sealed partial class workflow1: sequentialworkflowactivity
{< br> Public workflow1 ()
{< br> initializecomponent ();
}

Private VoidCodeactivityappsexecutecode (ObjectSender, eventargs E)
{
Console. writeline ("Hello workflow!");
}
}
}

 

 

How can I call a workflow after it is written?See the code in program. CS.

Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. Threading;
Using System. workflow. runtime;
Using System. workflow. runtime. Hosting;

Namespace Helloworkflow
{
Class Program
{
Static   Void Main ( String [] ARGs)
{
// When running a workflow and executing the workflow just defined
Using (Workflowruntime =   New Workflowruntime ())
{
/* Autoresetevent: A thread synchronization class used to release a single waiting thread. A workflow is actually executed on a separate thread created and managed during Workflow running,
This is because the workflow must be able to process multiple workflows simultaneously during running. In this example, two threads need to be synchronized, namely the workflow thread and the main thread of the host console application.
*/
Autoresetevent waithandle =   New Autoresetevent ( False );
// To let the host console application know when the workflow is finished, the Code subscribes to two workflowruntime events. The event uses the anonymous retrieval syntax. //Workflow completion event
Workflowruntime. workflowcompleted + =   Delegate ( Object Sender, workflowcompletedeventargs E)
{
// The code sends a signal to the autoresetevent object to notify it to release the console application. If an error occurs, the workflowterminated event is triggered.
Waithandle. Set ();
}; //Workflow exception event
Workflowruntime. workflowterminated + =   Delegate ( Object Sender, workflowterminatedeventargs E)
{
// Display Error code information and release the waiting thread
Console. writeline (E. Exception. Message );
Waithandle. Set ();
};

// others workflow workflow1 real column
workflowinstance instance = workflowruntime. createworkflow ( typeof (helloworkflow. workflow1); /// Start workflow workflow1
instance. start ();

// waitone: blocks the current thread, until the current waithandle receives the signal.
waithandle. waitone ();

Console. writeline ("Press any key to exit");
Console. readkey ();
}
}
}
}

 

Such a simple workflow is ready. For each step of explanation, see the comments in the code. The creation and running methods of other workflows are similar.

Run the command to view the result.

 

 

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.