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

Top 5 Contributors of the Month
Post New Web Links

Loading persisted workflow instances with WorkflowApplication

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

I understand I may be doing this wrong.  I read the topic at http://social.msdn.microsoft.com/Forums/en-CA/wfprerelease/thread/a11eb75d-65de-4787-9745-2fd634d0eee9 but I still don't get it, exactly.

I have an application that uses WorkflowApplications to handle the workflows.  I have a workflow that contains a one minute Delay activity.  When this activity is hit, the workflow Idles, persists (SqlWorkflowDataStore), and unloads.  This is all fine.  If the app runs for the minute, it will be resumed and will complete.

However, if I stop the app during the minute that it is delayed, and then start it up again at some point later, the workflows do not resume.  A little digging shows that WorkflowApplication does not resume automatically, and that I have to do that manually.  That's fine.  The problem is, I don't know how.

I see there is a WorkflowApplication.LoadRunnableInstance, and I see in the db that there are records in the RunnableInstancesTable table.  But when I call LRI, I get back this:

System.Runtime.DurableInstancing.InstancePersistenceCommandException was unhandled
  Message=In order to match and load a runnable instance in the store, the requesting InstanceOwner must have specified a workflow host type when it was created. To do so, add a key-value pair to the CreateWorkflowOwner

View Complete Post

More Related Resource Links

Foundations: Loading Workflow Models in WF


When building workflows, you must consider the developer experience, available tools, long-term maintenance, and future versioning.

Matt Milner

MSDN Magazine May 2008

InfoPath Workflow Task Form "Loading" event handler only being called after App Pool recycled.


I have a Workflow that is using an InfoPath task form.  In the "FormEvents_Loading" method event handler I have some code that needs to run each time the form is opened.   I recycle the App Pool and open the form the code runs perfectly, but if I close and try to re-open the form the code is not run at all.  I can then recycle the App Pool again and on the next load the code executes just fine.   The code that is supposed to be run is a very simple statement to set a field value, so I don't think it is interfering.

Does anyone know what this might be?


How to run multiple instances of workflow



I've created simple sequential workflow. It's only creates one task and is waiting in while loop until task is Approved. It works fine when I run only one instance of this workflow, but if I start another instance before first one is finished it gets stack and doesn't complete task an workflow stays in In Progress state forever.

Error loading workflow services

Hello, I'm developing a service library using the new wf 4.0 and one of my requirements is that some activities have the ability to be resumed by a client, so i created a wcf resume service that could load a workflow definition and resume a bookmark of that workflow. One of the services i created was a flowchart that has a receive reply activites inside a sequence activity has a start point, after that i have another sequence that have another sequence, yes 2 sequence activities, and my custom activity that needs to be resumed by a client. The 2 nested sequence activites was a something i used only for testing, but if i had those 2 sequence activities nested i got an error when loading that workflow definition in my resume service: 'ObtemPareceres' is not of type 'Sequence'. When loading this instance you must ensure that the activity with name 'ObtemPareceres' implements 'Sequence'. The "ObtemPareceres" is my custom activity, and if i remove that second nested sequence everything works fine. Anyone has any idea of whats going where? thanksFrederico Regateiro

How do I set PrimitiveDataProperties Value in the Workflow DurableInstancing.Instances Table

Hi, I'm simply trying to persist my Variables (or designated Variables) from my Workflow and I came across this article (http://msdn.microsoft.com/en-us/library/ee960223.aspx) on how to read the Values from the PrimitiveDataProperties Column in the DurableInstancing.InstancesTable, but I can't seem to find any documenation on how to save the Variables to this Column.  I thought my Variables would automatically save into the PrimitiveDataProperties Column after persisting, but it does not. I only find articles about using Promotable Properties or Tracking Participants in order to get Data out of a Workflow Instance, but both require configuration and/or custom Views in the Persistence Database, etc.  I simply just want to have my Variables persisteced when I use the PersistActivity and  then be able to read them at a later time. Thanks Devaron Ruggiero

Suspend / Resume Instances within Workflow Service Host (in Windows Service)

We are hosting WF 4 worklfow instances within a Windows Service that uses the Workflow Service host container.   On the Windows Service OnStart we start the workflow service host (w/ multiple WCF endpoints such as start workflow instance, cancel workflow instance, poll workflow instance status, etc.) and these endpoints create or work on one or more long running workflow instances.     My question is, if a user attempts to stop the Windows Service while workflow instance(s) are running, what is the best way to manage this scenario.   Our inclination is to persist these workflows (using sql persistence) and then on the next start of the Windows Service, resume these workflow instances and allow them to continue to completion.    In OnStart, we have a handle to the Workflow Service host.    How can we iterate through all the active workflow instances in OnStop and then in OnStart, resume these after the workflow service host is opened and running?   Are there are any methods of managing this scenario?    Thanks

Unloading persisted states causes workflow problems



We are using WF 3.5 with a SqlWorkflowPersistenceService with the ownershipduration set at 2 hours and the loadingInternval at 1 hour.  We are finding that on certain occasions, rehydrated or attempts to rehydryate a persisted state results in some unusual behaviour. Of particular note, has been two of the same instance running and subsquently one fails (e.g. the first one removes data from a server, the second one attempts the same op -to remove the same data and subsquently fails becasue it was already removed by the first). In some cases, it almost resembes race conditions of two of the same instances!  Trying to replicate or reproduce the issue can be diffucult, but the closest I can get appears to be shortening the ownership interval in a running workflow instance resulting in

System.Workflow.Runtime.Hosting.PersistenceException: This workflow is not owned by the WorkflowRuntime. The WorkflowRuntime's ownership has expired, or another WorkflowRuntime owns the workflow.

but Im not sure if this is the problem.  Does this sound like an ownership issue with a particular workflow runtime? If so, I fail to see how two instances could run at once (I would have thought WD/Sql persistence server would prevent this from occurring)?

Any help would be greatly appreciated,




WindowsApplication executing two WorkflowApplication instances within one transaction



Let's assume we would like to have a WindowsApplication which should be executing two WorkflowApplication instances within one transaction.


We could imagine a button click event handler which should:

  1. Start the transaction.
  2. Execute WorkflowApplication1.
  3. Execute WorkflowApplication2.
  4. Commit the transaction.

Should I just create a TransactionScope and somehow pass it to the WorkflowApplications? If yes, how to pass the TransactionScope to the WorkflowApplications, must this be done explicitly or is it done implicitly?



Best regards,

Henrik Dahl


How To Reload a Persisted Workflow with WorkflowServiceHost


We are using Workflow Foundation 4 Beta 2 with a client / server architecture where the client runs workflow through the server  using a WorkflowServiceHost. The client itself runs no workflow. The workflow is long running, requiring that it persist while awaiting user input. We have set up correlation and persistence such that the user can successfully move the workflow from one activity to another. The problem occurs when the workflow is unloaded or the server application is restarted; we are unable to determine how to continue a workflow that has been unloaded. We have looked at numerous samples such as the Hiring Request Process (http://msdn.microsoft.com/en-us/library/ee622985(VS.100).aspx) and the samples demonstrate the same issue…everything works great until the workflows are unloaded or the server (application running the workflowservicehost) is restarted. There is no exception thrown by the client call, the workflow simply doesn’t move forward.

Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventRecei


Hi all, i found the below error in event log. How can i fix this issue.

Event ID: 6875            Source: Windows SharePoint Services 3

Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver in Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.

: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Please help me out in this issue. Thanks in advance.


K2Blackpearl, Sharepoint, .Net

How can you invoke a Workflow from within a running WorkflowApplication?


Our app has this concept of being able to "embed" workflows inside other workflows.  So, we have a custom activity called EmbedWF.  In the EmbedWF's execute handler, we are essentially loading the XAML workflow definition of a particular workflow ... and then we need to invoke it, or run it. 

The parent workflow is hosted in a WorkflowApplication instance ... it uses persistance, navigation, etc.  The idea is that when it executes and comes to an instance of an EmbedWF activity, we want to then kick off that other embedded workflow. 

Is there a good way to do this? 

I've tried this (from the Execute event of the EmbedWF activity):

          WorkflowInvoker wfi = new WorkflowInvoker(activity);
          IDictionary<string, object> resultArgs = wfi.Invoke(args);


But that's just causing the workflow application to hang when it's running UI activities.  I've also tried this:


Caching data to share between workflow instances


I have a wf4 workflow that correlates an SMS message to an internal input channel. For part of the workflow I have a code activity that uses LINQ to SQL to load up a bunch of input channels (rows from a table) from a SQL db. For each workflow instance, the query is run each time against the db.

Is there a mechanism or model people use to cache this sort of stuff (table data) so that each workflow instance can use that instead of re-querying?

Why does a workflow I set up in Sharepoint not appear when loading Sharepoint Designer?

I can create an approval workflow using Sharepoint Designer, which appears to work (except for the notifications, which are decidedly ropey) and create another just using the Sharepoint three stage workflow, which is equally ropey.  When I try to view the latter in SPD, there is no trace of it.  How do I get the Sharepoint created workflows to appear in SPD so that I can edit them at that level?

Create multiple workflow instances from within the workflow


I am creating workflow service that uses a pick activity with multiple pick branches having multiple ReceiveActivity instances, the first pick branch supports workflow initialization by using RecieveAndSendReply activity, CanCreateInstance property is set to 'true', while others use the initialized workflow (they have Receive activity only and CanCreateInstance property is set to false). Content-based correlation is used. The workflow is working without any problem.

But It does not work when I call the service operation of the first pick branch from one of other branches.  I want to create a new instances of the same worklow by calling the initilization branch. What is best way to accomplish this?


Loading and resuming workflow


Hi fellows,

I am having this problem that after programmatically loading my workflow from InstanceStore, my variables & input argumwnt where were stored before are unable to deserialized properly.

One of my veriable is a custom object which contians data members of other custom classes. After loading the instance i still have my variable but all of it members were null. Althought all of my custom classes are marked with Serializable Attribute.

What am i missing here?

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.

Multiple Instances of User Control


I have a user control that I place on a page severl times.  When I make a selection on a ddl in one one control the SelectedIndexChanged event fires for all the control on the page for that ddl.  So I get duplication of an insert that I do.  Is there a way to make sure these events are isolated so this doesn't happen.


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