static void Main(string[] args) { _event = new AutoResetEvent(false); bool more = true; int result = 0; var activity = new AccumulatorActivity(); var accumulator = new WorkflowApplication(activity); accumulator.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) => { result = (int)e.Outputs["Sum"]; more = false; _event.Set(); }); accumulator.Extensions.Add(new Notification(NotifySum)); accumulator.Run(); while (more) { Console.Write("Enter number: "); int number = int.Parse(Console.ReadLine()); accumulator.ResumeBookmark("GetNumber", number); _event.WaitOne(); } Console.WriteLine("Result is " + result); }
static WorkflowApplication CreateWorkflowApplication(AccumulatorActivity activity, InstanceStore instanceStore) { var application = new WorkflowApplication(activity); application.InstanceStore = instanceStore; application.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) => { _result = (int)e.Outputs["Sum"]; _more = false; _event.Set(); }); application.PersistableIdle = new Func<WorkflowApplicationIdleEventArgs, PersistableIdleAction>((e) => PersistableIdleAction.Unload); application.Extensions.Add(new Notification(NotifySum)); return application; }
static void Main(string[] args) { var instanceStore = CreateInstanceStore(); _event = new AutoResetEvent(false); var activity = new AccumulatorActivity(); var application = CreateWorkflowApplication(activity, instanceStore); var applicationId = application.Id; application.Run(); while (_more) { Console.Write("Enter number: "); int number = int.Parse(Console.ReadLine()); application = CreateWorkflowApplication(activity, instanceStore); application.Load(applicationId); application.ResumeBookmark("GetNumber", number); _event.WaitOne(); } Console.WriteLine("Result is " + _result.ToString()); }
internal WorkflowApplication CreateWorkflowApplication(AccumulatorActivity activity, InstanceStore instanceStore) { var application = new WorkflowApplication(activity); application.InstanceStore = instanceStore; application.Unloaded = new Action<WorkflowApplicationEventArgs>((e) => { this.Suspended = true; this.SyncEvent.Set(); }); application.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) => { this.Sum = (int)e.Outputs["Sum"]; this.Completed = true; this.SyncEvent.Set(); }); application.PersistableIdle = new Func<WorkflowApplicationIdleEventArgs, PersistableIdleAction>((e) => PersistableIdleAction.Unload); application.Extensions.Add(new Notification(NotifySum)); this.Suspended = false; return application; }