.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Flowchart workflow, Delay seems to hold thread

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :Windows Application

When I create a Flowchart workflow with a delay, and run it via WorkflowApplication.Run(), then try to terminate the main program thread, I would expect the workflow would terminate without a problem because the Delay has relinquished the ThreadPool thread.  But it does not.  If I don't cancel every running workflow, the application will not terminate.

I should say that when my process ends, I just want the workflows to go away.  I don't need to persist them.  When I run the program again, I'll just start over.

To demo this problem, I created a simple app.  I run a flowchart workflow that has a 10-second Delay, then a WriteLine("here") then loops back to the delay.  There's no way out of this loop.

I know I can keep a list of all the WorkflowApplication instances, and loop through them when I stop.  But why do I need to?  What is keeping my process from terminating?  Is there a way to change this? 

I invoke the workflow using this code: 

class Program


 static void Main(string[] args)


  WorkflowApplication app = new WorkflowApplication(

View Complete Post

More Related Resource Links

System.InvalidOperationException: Instance operation is not valid on workflow runtime thread

Am getting the exception related in the title of this article when using the StateMachineWorkflowInstance object to arbitarily set state in my workflow code; and am unsure why.  The code follows below:   500     Protected Overrides Function Execute(ByVal executionContext As System.Workflow.ComponentModel.ActivityExecutionContext) As System.Workflow.ComponentModel.ActivityExecutionStatus   501    502    506         Dim smwi As StateMachineWorkflowInstance = New StateMachineWorkflowInstance(StaticWFRuntime.LocalRuntime, Me.WorkflowInstanceId)   511    512         'set workflow-wide database connection string   513         _connectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString   518    519         Utility.LogEnabled()   520    521         Utility.FoaeaLogger.WriteEntry("Processing TracingApplication.Execute()....", EventLogEntryType.Information)   522         If StaticWFRuntime.LocalRuntime Is Nothing OrElse StaticWFRuntime.LocalRuntime.IsStarted = False Then   523             Utility.FoaeaLogger.WriteEntry("No static RuntimeService object exists!", EventLogEntryType.Warning)   524         End If   525    526         Return MyBase.Execute(executionContext)   527    528     End Function   796     Private Sub gotoState2_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)   797    798        

Delay Activity is not working with SharePoint state machine workflow

Hello,   I have a problem with Delay Activity in Sharepoint state machine workflow. This issue is kind of common to many people but so far I haven't come accross any working solution. In one of the workflow states, I want to add a delay activity to send email notification if no action is taken after certain time. Below is what I have done:   In the targeted state: 1) add one eventDriven activity to handle the normal process (approve the item) 2) add another eventDriven activity to send the reminder email. In this eventDriven activity, I first add a delayActivity, set it to 2 minutes for test purpose. Then I add a Sharepoint SentEmail activity.   With my test, the Dealy Activity is never invoked after timeout period. What should I do to make the delay activity work in the SharePoint state machine workflow? Is there any work around if the delay activity is simply not working there?   Any suggestions are appreciated.

Flowchart workflow, custom "FlowDecision" activity?

Dear all, in order to simplify the workflow "design" we would like to build our own activities that return a result with one or more nodes. Something like the "True/False" nodes that come out of the FlowDecision Activity. I know that one could normally add a FlowDecision activity after our custom activity and insert the condition expression to redirect the flow based on the result... however this requires the ability to know the "content" of the previous activity, and for some users we're targeting it's not immediate. Thank you!Adriano

ASP.Net + State Machine Workflow + Delay Activites

We have been developed an approval/rejection/Escalation 3 level State machine worklfow which has been hosted in an ASP.Net application. For escalation we are using multiple delay activities. We have deployed the ASP.Net application in a server. The application is running perfectly as we were expecting when the server is in unlocked state. But Once the server is in Locked or Logged off state the escalation part of the workflow is not functioning as required. Please give us suggestions as we are unable to identify what the issue is?

Thanks any suggestions.

windows workflow 4.0 flowchart


Hi I am new to workflow and currently making one sample application in which there are 4 different roles. 1) creator 2) 1st approver 3) reviewer and 4) 2nd approver. I make  flowchart and code activities for all type of users and flow of application is like "Creator create ticket and then 1st approver approve/reject/sendforreview that ticket, if approve then 2nd approver approve/reject it else if sendforReview then reviewer approve/reject it, after approval of reviewer 2nd approver will approve/reject the same.

I have one table of my application in sql server and others are created by execute script of WF 4.0.

When creator creates ticket then how 1st level approver will get all records submitted by creator and pending for actions by workflow?

and also how reviewer and 2nd approvers will get records in their queue by workflow not by applying manual logic to select based on approval status flag.


FlowChart workflow - Custom FreeformActivityDesigner sample



       Here is the long due sample for writing custom activity designers utilizing the freeform activitydesigner. This is still a very crude sample, so we will try to post improved versions from time to time.  Thanks to Arjun for the Executors and Validators. The validators show a false positive sometimes because of a bug that we will be fixing soon.


here is a preview of the flowchart workflowtype  get


State Machine Workflow + External Event + Delay activity



I have state machine workflow with a state contain 2 event driven activities, one is waiting for an external event, and second one is delay. If the external event didn't happen within specified time, timeout occurs and send email. But if the external event delivered, it transited to next state.


Both situation works fine. But once the external event occurred and transited to next state, the delay activity time out happens and it sends the mail. I don't want it happen, When i read through various blog, I learnt that once the workflow instance moved to next state, all event subscriptions related to the previous state are removed from the queue.... But it is not happening in my situation

Kindly help me to find where i am going and to resolve this issue..


p.s I set manualworkflow scheduler  - useActiv

Can I use Thread.Sleep() instead of delay acitivity..

Basically I want to pause the activity for 20mins. I just simply use Thread.Sleep() method.. Should I use delay activity..
- What is the difference between Thread.Sleep() and delay activity..?

Free Series of SharePoint Workflow How-to Videos

This is the series of "How to" Document Workflow with SharePoint using Visual Studio 2008 (using the .NET Framework 3.0 for backward compatibility to Visual Studio 2005). I have created video's that show the most common requests that I have seen around MOSS/SharePoint 2007 workflow & document workflow.

Thread Performance: Resource Contention Concurrency Profiling in Visual Studio 2010


Visual Studio 2010 includes new resource contention profiling features that help detect concurrency contention among threads. We walk through a profiling investigation to demonstrate how you can pinpoint and fix resource contention problems in your code.

Maxim Goldin

MSDN Magazine June 2010

Workflow Services: Visual Design of Workflows with WCF and WF 4


The .NET Framework 4 makes it easier than ever to implement WCF services using WF. We'll demonstrate just how easy it is by modeling a long-running, durable and instrumented workflow based on a real-world business case without having to write any code.

Leon Welicki

MSDN Magazine May 2010

Thread Diagnostics: Performance Tuning with The Concurrency Visualizer in Visual Studio 2010


Understanding performance bottlenecks in multithreaded apps used to require significant instrumentation and analysis by expert developers. The Concurrency Visualizer in Visual Studio 2010 significantly reduces the burden of parallel performance analysis.

Hazim Shafi

MSDN Magazine March 2010

Workflow Essentials: Collaborative Workflow Improvements in SharePoint 2010


In this article, the author covers the new features in SharePoint 2010 geared for workflow developers and then walks the reader through a couple of new user scenarios.

Paul Andrew

MSDN Magazine November 2009

Foundations: Workflow Services for Local Communication


This month's column describes how to use WCF for communication between a workflow and a host application in Windows Workflow Foundation 3. This knowledge should help developers with their efforts using WF3 and prepare them for WF4, where WCF is the only abstraction over queues (referred to as "bookmarks" in WF4) that ships with the framework.

Matthew Milner

MSDN Magazine November 2009

Foundations: Windows Workflow Design Patterns


Design patterns provide a common, repeatable approach to solving software development tasks, and many different patterns can describe how to accomplish a certain goal in code. When developers begin working with Windows Workflow Foundation (WF), they often ask about how to accomplish common tasks with the technology. This month's column discusses several design patterns used in WF.

Matthew Milner

MSDN Magazine August 2009

ASP.NET Workflow: Web Apps That Support Long-Running Operations


Integrating workflow into ASP.NET applications means communicating with activities via a workflow queue and hosting the runtime in the global application class. We'll show you how.

Michael Kennedy

MSDN Magazine January 2009

Real-World WF: Best Practices For Windows Workflow Foundation Apps


The heart of Windows Workflow Foundation is its declarative programming model. Here are some best practices to consider when using WF to realize software solutions in the real world.

Josh Lane

MSDN Magazine December 2008

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend