官术网_书友最值得收藏!

Using Variable in a WF program

We can use Variable temporarily to store a value when a WF program is running. In this task, we will create a WF program that prints five numbers to the console in a loop. We will use the NumberCounter variable as a number counter.

How to do it...

  1. Create a workflow project:

    Create a new Workflow Console Application under the Chapter01 solution and name the project as UseVariable.

  2. Author a workflow:

    Add a Sequence activity, click the Sequence activity, create an Int32 NumberCounter variable, and set its Scope to Sequence. Then, author the workflow as shown in the following screenshot. In the second Assign activity type NumberCounter=NumberCounter+1.

    How to do it...
  3. Run it:

    Set UseVariable as Startup project. Press Ctrl+F5 to build and run the workflow without debugging. The application should run in a console window and print the following message:

    How to do it...

How it works...

To make the workflow logic easy to understand, translate the workflow into C# code. It will look like:

int NumberCounter = 0;
do 
{
    Console.WriteLine(NumberCounter);
    NumberCounter++;
}while (NumberCounter <= 5);

While we can use arguments to flow data into and out of a workflow, we use Variable to store data in a workflow. Every variable has its scope, and can be accessed by activities within its scope. Variable in WF4 is pretty much like variables in imperative language such as C#.

There's more...

Please note that we cannot access to the workflow variables from the outside host. WF4 variables are designed for sharing data inside the workflow instance. We can use Bookmark to access the workflow from the outside host.

See Also

  • Customizing a MyReadLine activity with Bookmark
主站蜘蛛池模板: 广西| 平和县| 塘沽区| 沙雅县| 呼和浩特市| 花莲市| 朔州市| 桦川县| 柘荣县| 邻水| 札达县| 无极县| 道孚县| 大埔区| 漾濞| 和林格尔县| 龙口市| 南城县| 宁化县| 娄烦县| 贵阳市| 鄂州市| 合肥市| 合水县| 保山市| 崇义县| 辽阳市| 平湖市| 堆龙德庆县| 洛宁县| 新营市| 岑溪市| 探索| 宁阳县| 大英县| 安图县| 阳东县| 马边| 榆树市| 永新县| 无棣县|