In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章将为大家详细讲解有关Visual Studio 2010中WF 4.0怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
最近在虚拟机中安装了Visual Studio 2010。界面是WPF的,CPU和内存占用不是很夸张,打开一个很简单的附带的Lab Project, CPU使用率一般在20%一下,内存使用不到800M。
言归正传,还是来介绍Windows Workflow 4.0。
与3.5相比工作流模型有了很大改变和不同。
我们知道3.5中工作流都是托管在WorkflowRuntime中的,通过WorkflowRuntime来创建、执行工作流实例;在4.0中没有WorkflowRuntime类,可以方便的直接创建WorkflowInstance实例和执行工作流。Lab中代码如下:
WorkflowInstance myInstance = new WorkflowInstance(new SayHello(), new SayHelloInArgs(userName)); myInstance.OnCompleted = delegate(WorkflowCompletedEventArgs e) { Console.WriteLine("*** OnCompleted delegate is running on thread {0} ***", Thread.CurrentThread.ManagedThreadId); SayHelloOutArgs outArgs = new SayHelloOutArgs(e.Outputs); greeting = outArgs.Greeting; syncEvent.Set(); }; myInstance.OnUnhandledException = delegate(WorkflowUnhandledExceptionEventArgs e) { Console.WriteLine(e.UnhandledException.ToString()); return UnhandledExceptionAction.Terminate; }; myInstance.OnAborted = delegate(WorkflowAbortedEventArgs e) { Console.WriteLine(e.Reason); syncEvent.Set(); }; myInstance.Run();
4.0中有一个WorkflowInvoker类,这个类也可以执行工作流,只不过这个类是用来测试工作流的,这很大的改进了前一版本中工作流难以测试的问题。
[TestMethod] public void ShouldReturnGreetingWithName() { Dictionary input = new Dictionary() { {"UserName", "Test"} }; IDictionary output; output = WorkflowInvoker.Invoke(new SayHello(), input); Assert.AreEqual("Hello, Test from Workflow 4", output["Greeting"]); }
3.5中Activity是所有活动的基类,要实现自定义活动,只需重写Activity 的Execute()方法;在4.0中所有的活动都是从抽象类WorkflowElement派生出来的,而且Visual Studio中默认自定义活动都是从CodeActivity或CodeActivity继承的,相似的是也需要重写Execute()方法,从而实现自定义执行逻辑。
public class MyActivity1 : CodeActivity { protected override void Execute(CodeActivityContext context) { //你的实现代码 } }
当然,你还是可以从Activity派生自定义活动,不过与3.5有很大不同。
public class SayHelloInCode : Activity { protected override WorkflowElement CreateBody() { return new Sequence() { Activities = { new WriteLine() { Text = "Hello Workflow 4 in code" } } }; } }
4.0中新增加的工作流服务功能,可以直接把工作流发布为WCF服务,当然工作流也必须设计为具有WCF应答功能才行。4.0提供4个与WCF相关的活动:Receive、ReceiveReply、Send、SendReply,通过这些活动可以可视化定义WCF的服务操作。
4.0中实现了工作流设计器的基本模型,可以很容易的实现自定义设计器。
关于"Visual Studio 2010中WF 4.0怎么用"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.