- Microsoft Windows Workflow Foundation 4.0 Cookbook
- Andrew Zhu
- 336字
- 2021-04-13 17:00:34
In this task, we will create the same "HelloWorkflow" function workflow using pure C# code, beginning from a Console Application.
- Create a Console Application project:
Create a new Console Application project under the
Chapter01
solution. Name the projectHelloCodeWorkflow
. The following screenshot shows the Console Application new project dialog: - Add reference to the
System.Activities
assembly:By default, a new Console Application doesn't have reference to the
System.Activities
assembly, due to which we need to perform this step. - Create workflow definition code:
Open
Program.cs
file and change the code present as follows:using System.Activities; using System.Activities.Statements; namespace HelloCodeWorkflow { class Program { static void Main(string[] args) { WorkflowInvoker.Invoke(new HelloWorkflow()); } } public class HelloWorkflow:Activity { public HelloWorkflow() { this.Implementation = () => new Sequence { Activities = { new WriteLine(){Text="Hello Workflow"} } }; } } }
- Run it:
Set
HelloCodeWorkflow
asStartUp
project and press Ctrl+F5 to run it. As expected, the result should be just like the previous result shown.
We use the following namespaces:
using System.Activities; using System.Activities.Statements;
Because WorflowInvoker
class belongs to System.Activities
namespace. Sequence
activity, WriteLine
activity belongs to System.Activities.Statements
. namespace.
public class HelloWorkflow:Activity { public HelloWorkflow() { this.Implementation = () => new Sequence { Activities = { new WriteLine(){Text="Hellow Workflow"} } }; } }
By implementing a class inherited from Activity, we define a workflow using imperative code.
WorkflowInvoker.Invoke(s);
This code statement loads a workflow instance up and runs it automatically. The WorkflowInvoker.Invoke
method is synchronous and invokes the workflow on the same thread as the caller.
- Final Cut Pro X 影視包裝剪輯完全自學(xué)教程(培訓(xùn)教材版)
- 對(duì)比Excel,輕松學(xué)習(xí)SQL數(shù)據(jù)分析
- 從零開(kāi)始學(xué)LATEX
- Protel DXP 2004 SP2原理圖與PCB設(shè)計(jì)(第4版)
- Joomla! 1.5 SEO
- Excel 2010 商務(wù)數(shù)據(jù)分析與處理(第2版)
- Google App Engine Java and GWT Application Development
- Photoshop CS6實(shí)戰(zhàn)從入門(mén)到精通(超值版)
- SOLIDWORKS中文版實(shí)用教程
- Photoshop CS6案例教程(第3版)
- 剪映+Vlog+Premiere短視頻制作從新手到高手
- Photoshop CS6平面設(shè)計(jì)實(shí)戰(zhàn)從入門(mén)到精通(經(jīng)典暢銷(xiāo)版)
- 中文版Photoshop平面設(shè)計(jì)入門(mén)教程
- 玩轉(zhuǎn)電子設(shè)計(jì):基于Altium Designer的PCB設(shè)計(jì)實(shí)例(移動(dòng)視頻版)
- Plone 3 Theming