WEB开发网
开发学院软件开发C语言 WF4.0 Beta1之旅(3):全新的FlowChart 阅读

WF4.0 Beta1之旅(3):全新的FlowChart

 2010-10-01 08:29:03 来源:WEB开发网   
核心提示: Scope内可见:变量:Name:Target type:Int32 Scope:FlowChart Name:Guess type:Int32 Scope:FlowChartFlowChart中的设计如下图:这个图中就是实现我们猜数字逻辑的部分,这里有两个FlowDecision,WF4.0

Scope内可见:

变量:Name:Target type:Int32 Scope:FlowChart

Name:Guess type:Int32 Scope:FlowChart

FlowChart中的设计如下图:

WF4.0 Beta1之旅(3):全新的FlowChart

这个图中就是实现我们猜数字逻辑的部分,这里有两个FlowDecision,第一判断是否猜对了,如果猜对了流程就结束了,如果猜错了就会提示用户是猜大了

还是小了,让流程回退,用户重新猜.

四:宿主程序

class Program
{
  static void Main(string[] args)
  {
    AutoResetEvent syncEvent = new AutoResetEvent(false);
    var wfparams = new Dictionary<string, object>() { { "MaxNumber", 50 } };

    WorkflowInstance myInstance = new WorkflowInstance(new Flowchart1(), wfparams);
    myInstance.OnCompleted = delegate(WorkflowCompletedEventArgs e)
    {
      int Turns = Convert.ToInt32(e.Outputs["Turns"]);
      if (Turns != 0)
      {
        Console.WriteLine("恭喜您猜对了,次数{0}", Turns);
      }
      syncEvent.Set();
    };
    myInstance.OnAborted = delegate(WorkflowAbortedEventArgs e)
    {
      Console.WriteLine(e.Reason);
      syncEvent.Set();
    };
    myInstance.OnUnhandledException = delegate(WorkflowUnhandledExceptionEventArgs e)
    {
      Console.WriteLine(e.UnhandledException.ToString());
      return UnhandledExceptionAction.Terminate;
    };
    myInstance.Run();
    //syncEvent.WaitOne();
    while (!syncEvent.WaitOne(10, false))
    {
      if (myInstance.GetAllBookmarks().Count > 0)
      {
        bool validEntry = false;
        while (!validEntry)
        {
          int Guess;
          if (!Int32.TryParse(Console.ReadLine(), out Guess))
          {
            Console.WriteLine("Please enter an integer.");
          }
          else
          {
            validEntry = true;
            myInstance.ResumeBookmark("EnterGuess", Guess);
          }
        }
      }
    }


  }
}

 

五:运行结果如下

WF4.0 Beta1之旅(3):全新的FlowChart

六:相关文章

WF4.0 Beta1之旅(1):基本介绍

WF4.0 Beta1之旅(2):异常处理

上一页  1 2 3 4 

Tags:WF 之旅

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接