<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Windows Workflow</title><link>http://blogs.interknowlogy.com/joelrumerman/category/84.aspx</link><description>Windows Workflow</description><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.111</generator><item><dc:creator>Joel Rumerman</dc:creator><title>Dynamically Adding an Activity to an Executing Windows Workflow at Runtime</title><link>http://blogs.interknowlogy.com/joelrumerman/archive/2006/05/25/2756.aspx</link><pubDate>Thu, 25 May 2006 08:47:00 GMT</pubDate><guid>http://blogs.interknowlogy.com/joelrumerman/archive/2006/05/25/2756.aspx</guid><description>&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;I&amp;#8217;m currently working on an application that uses &lt;a href="http://www.windowsworkflow.net/Default.aspx?tabindex=0&amp;tabid=1" target="_blank"&gt;Windows Workflow Foundation&lt;/a&gt; to dynamically create parts of a user interface. I recently came across a situation where I needed to dynamically add and then execute a workflow activity based upon metadata parameters that were passed into the workflow. &lt;a href="http://blogs.msdn.com/markhsch/archive/2005/09/23/473373.aspx"&gt;Mark Schmidt&amp;#8217;s: Dynamic Update 101 for Windows Workflow Foundation&lt;/a&gt; blog entry was an excellent starting point, but while his example involves modifying the workflow once it starts, he modifies the workflow from within the runtime environment; I need to modify it from within the workflow itself. (Also, on a small side note, Mark&amp;#8217;s example is against a previous release of &lt;a href="http://www.windowsworkflow.net/Default.aspx?tabindex=0&amp;tabid=1"&gt;Windows Workflow&lt;/a&gt; and a few commands have changed.) While there isn&amp;#8217;t a whole lot of difference between Mark&amp;#8217;s approach and mine, there was one nuance at the end that I didn&amp;#8217;t expect and is worth noting.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;To modify the workflow I overrode the Execute method of the workflow. The Execute method code is the following:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;        &lt;span style="COLOR: blue"&gt;protected override&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;ActivityExecutionStatus&lt;/span&gt; Execute(&lt;span style="COLOR: #0066ff"&gt;ActivityExecutionContext&lt;/span&gt; executionContext)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;        {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;WorkflowChanges&lt;/span&gt; wfChanges = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;WorkflowChanges&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // get a handle to the transient workflow object&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;CompositeActivity&lt;/span&gt; transientWorkflow = wfChanges.TransientWorkflow;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // create the activity&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;ObjectHandle&lt;/span&gt; dynamicActivityHandle = &lt;span style="COLOR: #0066ff"&gt;Activator&lt;/span&gt;.CreateInstance(dynamicActivityAssembly, dynamicActivityType);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivityHandle == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;throw new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;ApplicationException&lt;/span&gt;("Activity: " + dynamicActivityType + " not found in " + dynamicActivityAssembly);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;Activity&lt;/span&gt; dynamicActivity = dynamicActivityHandle.Unwrap() as &lt;span style="COLOR: #0066ff"&gt;Activity&lt;/span&gt;;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivity == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;throw new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;InvalidOperationException&lt;/span&gt;("Activity Type: " + dynamicActivityType + " in " + dynamicActivityAssembly + " is not a valid activity");&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;DynamicActivityMarkerActivity&lt;/span&gt; dynamicActivityMarkerActivity = FindDynamicActivityMarkerActivity(transientWorkflow);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivityMarkerActivity != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; markerPosition = dynamicActivityMarkerActivity.Parent.Activities.IndexOf(dynamicActivityMarkerActivity);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    dynamicActivityMarkerActivity.Parent.Activities.Insert(markerPosition + 1, dynamicControlCompositionActivity);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // save the changes.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.ApplyWorkflowChanges(wfChanges);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;            }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;            &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;base&lt;/span&gt;.Execute(executionContext);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;        }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;The code is mostly plagiarized from Mark&amp;#8217;s example and he does a fine job of explaining it, but let&amp;#8217;s review the code anyways.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;WorkflowChanges&lt;/span&gt; wfChanges = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;WorkflowChanges&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // get a handle to the transient workflow object&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;CompositeActivity&lt;/span&gt; transientWorkflow = wfChanges.TransientWorkflow;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Creating a WorkflowChanges object creates a copy of the running Workflow. This is a necessary step because if we attempted to modify the running workflow and not a copy of it by say adding an activity to the activities collection (i.e. this.Activities.add(myNewActivity);) we would receive a runtime error stating we can&amp;#8217;t modify this collection at runtime. The WorkflowChanges provides the ability to make multiple changes to the workflow and then apply all of those changes at once. Mark relates this to a database transaction and I think that&amp;#8217;s a good analogy.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Executing the TransientWorkflow property on the WorkflowChanges just provides a pointer to the root CompositeActivity. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // create the activity&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;ObjectHandle&lt;/span&gt; dynamicActivityHandle = Activator.CreateInstance(dynamicActivityAssembly, dynamicActivityType);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivityHandle == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;throw new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;ApplicationException&lt;/span&gt;("Activity: " + dynamicActivityType + " not found in " + dynamicActivityAssembly);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;Activity&lt;/span&gt; dynamicActivity = dynamicActivityHandle.Unwrap() as &lt;span style="COLOR: #0066ff"&gt;Activity&lt;/span&gt;;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivity == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;throw new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;InvalidOperationException&lt;/span&gt;("Activity Type: " + dynamicActivityType + " in " + dynamicActivityAssembly + " is not a valid activity");&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;This code uses two parameters, dynamicActivityType and dynamicActivityAssembly and uses the System.Activator class to create an instance of the type contained within the assembly. It then does some basic error checking to ensure that the type was found and that it has a base type of System.Workflow.ComponentModel.Activity.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: #0066ff"&gt;DynamicActivityMarkerActivity&lt;/span&gt; dynamicActivityMarkerActivity = FindDynamicActivityMarkerActivity(transientWorkflow);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (dynamicActivityMarkerActivity != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                {&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; markerPosition = dynamicActivityMarkerActivity.Parent.Activities.IndexOf(dynamicActivityMarkerActivity);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                    dynamicActivityMarkerActivity.Parent.Activities.Insert(markerPosition + 1, dynamicControlCompositionActivity);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                // save the changes.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;                &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.ApplyWorkflowChanges(wfChanges);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;            }&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Here, I&amp;#8217;m finding the location of a marker activity (DynamicActivityMarkerActivity) within my workflow that I use as a reference point so I can customize where to insert the new activity. FindDynamicActivityMarkerActivity is just a helper function to find the marker activity. If I&amp;#8217;ve found my marker activity I proceed to insert the dynamic activity into the activities collection.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Finally, I apply the workflow changes to the running workflow using the ApplyWorkflowChanges command.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;At this point I thought that I was done and that my new activity would execute. The weird thing is that nothing happened. Furthermore, it seemed as my workflow stopped running after this point. Knowing that workflow uses an eventing model to communicate with its runtime I started adding event handlers to the workflow runtime events. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;m_workflowRuntime.WorkflowAborted += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowAborted);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowCompleted += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowCompletedEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowCompleted);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowIdled += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowIdled);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowLoaded += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowLoaded);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowStarted += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowStarted);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowSuspended += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowSuspendedEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowSuspended);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowTerminated += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowTerminatedEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowTerminated);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowCreated += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(workflowRuntime_WorkflowCreated);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;m_workflowRuntime.WorkflowResumed += &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #0066ff"&gt;EventHandler&lt;/span&gt;&lt;&lt;span style="COLOR: #0066ff"&gt;WorkflowEventArgs&lt;/span&gt;&gt;(m_workflowRuntime_WorkflowResumed);&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="COLOR: #0066ff"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;A good list and description of the events can be found at &lt;a href="http://blogs.msdn.com/moustafa/archive/2006/03/02/542459.aspx"&gt;Moustafa Khalil Ahmed's Space: Managing Workflow&amp;#8217;s Lifecycle&lt;/a&gt; blog entry. The event of interest in this problem was the WorkflowSuspended event. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 12pt"&gt;Placing a break point on the event handler I noticed that after this.ApplyWorkflowChanges (wfChanges) executed the breakpoint was hit. Diving into the SuspendedWorkflowEventArgs the reason property read: &amp;#8220;suspending to apply dynamic update to the instance&amp;#8221; It seems that the workflow is automatically suspended whenever changes are applied. Not knowing how to avoid the suspension at the moment, I blindly resume the suspended workflow.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="COLOR: blue"&gt;static void&lt;/span&gt; workflowRuntime_WorkflowSuspended(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; sender, &lt;span style="COLOR: #0066ff"&gt;WorkflowSuspendedEventArgs&lt;/span&gt; e)&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;{&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;            e.WorkflowInstance.Resume();&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;}&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;The WorkflowSuspendedEventArgs provides a pointer to the WorkflowInstance that is being suspended. I just resume that WorkflowInstance.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;I know that this could cause problems as there may be other reasons why a workflow is suspended other than because of the application of changes, but for now this gets me around my problem. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Once the workflow resumed my new activity executed. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Happy coding!&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;- Joel&lt;/p&gt;&lt;img src ="http://blogs.interknowlogy.com/joelrumerman/aggbug/2756.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>