static void OnWorkflowCompleted(object sender, WorkflowCompletedEventArgs e) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "Host", "Host: Processed WorkflowCompleted Event"); waitHandle.Set(); Console.WriteLine("\n--- Workflow Done ---\n"); }
protected override void Initialize(IServiceProvider provider) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "WaitForMessageActivity", "WaitForMessageActivity: Processed Initialization"); WorkflowQueuingService queuingService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); this.workflowQueue = queuingService.CreateWorkflowQueue("WaitForMessageActivityQueue", false); this.workflowQueue.QueueItemAvailable += this.HandleExternalEvent; }
private void HandleExternalEvent(Object sender, QueueEventArgs args) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "WaitForMessageActivity", "WaitForMessageActivity: Processed External Event"); object data = this.workflowQueue.Dequeue(); ActivityExecutionContext context = sender as ActivityExecutionContext; context.CloseActivity(); }
static void OnWorkflowIdled(object sender, WorkflowEventArgs e) { if (workflowRuntime.GetService <ManualWorkflowSchedulerService>() != null) { // Set a system timer to reload this workflow when its next timer expires SetReloadWorkflowTimer(); } else { readyHandle.Set(); } ThreadMonitor.WriteToConsole(Thread.CurrentThread, "Host", "Host: Processed WorkflowIdle Event"); Console.WriteLine("\n--- Workflow Idle ---\n"); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext context) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "WaitForMessageActivity", "WaitForMessageActivity: Processed Waiting For External Event"); return(ActivityExecutionStatus.Executing); }
private void OnCodeActivity3ExecuteCode(object sender, EventArgs e) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "ThreadingWorkflow", "CodeActivity3: Processed ExecuteCode Event"); }
public ThreadingWorkflow() { InitializeComponent(); ThreadMonitor.WriteToConsole(Thread.CurrentThread, "ThreadingWorkflow", "ThreadingWorkflow: Processed Constructor"); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage WorkflowThreading.exe [Single | Multi] [Delay | WaitForMessage]"); return; } if (!args[0].Equals("Single", StringComparison.OrdinalIgnoreCase) && !args[0].Equals("Multi", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Specify Single or Multi as a first command line parameter"); return; } if (!args[1].Equals("Delay", StringComparison.OrdinalIgnoreCase) && !args[1].Equals("WaitForMessage", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Specify Delay or WaitForMessage as a second command line parameter"); return; } ThreadMonitor.Enlist(Thread.CurrentThread, "Host"); Console.ForegroundColor = ConsoleColor.White; // Start the engine using (workflowRuntime = new WorkflowRuntime()) { ManualWorkflowSchedulerService scheduler = null; if (args[0].ToString().Equals("Single", StringComparison.OrdinalIgnoreCase)) { scheduler = new ManualWorkflowSchedulerService(); workflowRuntime.AddService(scheduler); } workflowRuntime.StartRuntime(); // Set up the workflow runtime event handlers workflowRuntime.WorkflowCompleted += OnWorkflowCompleted; workflowRuntime.WorkflowTerminated += OnWorkflowTerminated; workflowRuntime.WorkflowIdled += OnWorkflowIdled; workflowRuntime.WorkflowCreated += OnWorkflowCreated; // Load the workflow type Type type = typeof(ThreadingWorkflow); Dictionary <string, object> workflowParameters = new Dictionary <string, object>(); workflowParameters.Add("BranchFlag", args[1]); Console.WriteLine("\n--- Before Starting Workflow ---\n"); // Create an instance of the workflow workflowInstance = workflowRuntime.CreateWorkflow(type, workflowParameters); workflowInstance.Start(); Console.WriteLine("\n--- After Starting Workflow ---\n"); if (scheduler != null) { scheduler.RunWorkflow(workflowInstance.InstanceId); } readyHandle.WaitOne(); if (args[1].Equals("WaitForMessage", StringComparison.OrdinalIgnoreCase)) { // Send message to WaitForMessageActivity's queue workflowInstance.EnqueueItem("WaitForMessageActivityQueue", "Hello", null, null); } if (scheduler != null) { scheduler.RunWorkflow(workflowInstance.InstanceId); } waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } }
static void OnWorkflowCreated(object sender, WorkflowEventArgs e) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "Host", "Host: Processed WorkflowCreated Event"); }