WF4.0 BASICS (7) Use of data transmission variables and parameters

Source: Internet
Author: User

This section describes how to use the principles and skills of parameters and variables in WF4.0.

 

Download this example:

Http://files.cnblogs.com/foundation/VariablesAndArgumentsSample.rar

Examples

 

 

Use of data transmission variables and parameters

 

[Parameters] can be bound to [variables] in [expression mode ].

[In parameter]. The value of the correlated variable can be passed In. When the parameter is modified internally, the correlated variable is not changed.

Note:

1. Define a [InChangeActivity] with a string type [In parameter] myIn

Print the value of myIn in the [Execute] method, modify the value of myIn, and then print again

 

2. Add a string [myVariable] variable to the xaml workflow.

 

3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.

 

4. Add [InChangeActivity] and [InChangeActivity. myIn] To The xaml workflow and bind them to the [myVariable] variable.

 

5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].

 

InChangeActivity

Public sealed class InChangeActivity: CodeActivity

{

Public InArgument <string> myIn {get; set ;}

 

Protected override void Execute (CodeActivityContext context)

{

String s1 = context. GetValue (this. myIn );

System. Console. WriteLine ("input value: a: {0}", s1 );

 

//

Context. SetValue (myIn, Guid. NewGuid (). ToString ());

 

//

String s2 = context. GetValue (this. myIn );

System. Console. WriteLine ("Internal modification: {0}", s2 );

}

}

Workflow

Host

WorkflowInvoker. Invoke (new InChangeWorkflow ());

Result

 

 

 

[Out parameter] The correlated variable value cannot be passed in. When an internal parameter is modified, the associated variable is updated.

Note:

1. Define an [OutChangeActivity] with a string type [Out parameter] myOut

Print the value of myOut in the [Execute] method, modify the value of myOut, and then print it again.

 

2. Add a string [myVariable] variable to the xaml workflow.

 

3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.

 

4. Add [OutChangeActivity] and [OutChangeActivity. myOut] To The xaml workflow and bind them to the [myVariable] variable.

 

5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].

OutChangeActivity

Public sealed class OutChangeActivity: CodeActivity

{

Public OutArgument <string> myOut {get; set ;}

 

Protected override void Execute (CodeActivityContext context)

{

String s1 = context. GetValue (this. myOut );

System. Console. WriteLine ("input value: {0}", s1 );

 

//

Context. SetValue (myOut, Guid. NewGuid (). ToString ());

 

//

String s2 = context. GetValue (this. myOut );

System. Console. WriteLine ("Internal modification: {0}", s2 );

}

}

Workflow

Host

WorkflowInvoker. Invoke (new OutChangeWorkflow ());

Result

 

 

 

The value of the [In/Out parameter] correlated variable can be passed In. When the internal parameter is modified, the associated variable is updated.

Note:

1. Define a [InOutChangeActivity] with a string type [InOut parameter] myInOut

Print the value of myInOut in the [Execute] method, modify the value of myInOut, and print again

 

2. Add a string [myVariable] variable to the xaml workflow.

 

3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.

 

4. Add [InOutChangeActivity] and [InOutChangeActivity. myInOut] To The xaml workflow and bind them to the [myVariable] variable.

 

5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].

 

InOutChangeActivity

Public sealed class InOutChangeActivity: CodeActivity

{

Public InOutArgument <string> myInOut {get; set ;}

 

Protected override void Execute (CodeActivityContext context)

{

String s1 = context. GetValue (this. myInOut );

System. Console. WriteLine ("input value: a: {0}", s1 );

 

//

Context. SetValue (myInOut, Guid. NewGuid (). ToString ());

 

//

String s2 = context. GetValue (this. myInOut );

System. Console. WriteLine ("Internal modification: {0}", s2 );

}

}

Workflow

Host

WorkflowInvoker. Invoke (new InOutChangeWorkflow ());

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.