创建第一个Workflow项目
1. 创建Workflow项目 – 选择Workflow Console Application
2. 添加CodeActivity
3. 打开CodeActivity,添加一行代码到Execute方法中
public sealed class CodeActivity1 : CodeActivity
{
// Define an activity input argument of type string
public InArgument<string> Text { get; set; } // If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext context)
{
Console.WriteLine("The time is {0}", DateTime.Now.ToLongTimeString());
}
}
4. 编译,然后打开Workflow1.xaml文件,在工具栏中应该能看到新生成的CodeActivity1。
5. 依次拖动如下控件到xaml设计器上。Sequence -> CodeActivity1 -> Delay -> CodeActivity1。最终结果如下:
6. 修改Delay控件属性,将Duration改为10秒。
7. 修改Program.cs,添加读取字符代码用来暂停程序运行。
class Program
{
static void Main(string[] args)
{
Activity workflow1 = new Workflow1();
WorkflowInvoker.Invoke(workflow1); // Pause the display
Console.WriteLine("Press enter to continue.");
Console.Read();
}
}
8. 运行。结果如下: