locked
WorkflowApplication.Load takes a long time RRS feed

  • Question

  • When I load a persisted WF instance, I can watch a profiler of the DB activity.  From the time I step over .Load until I see the LoadInstance stored procedure execute is taking anywhere from 5 to 10 seconds.  Is there a way to alter this behavior?

    Here is how I am creating the Instance Store:

     public class WorkflowLoader : IDisposable
     {
      public SqlWorkflowInstanceStore InstanceStore { get; private set; }
      InstanceHandle mInstanceHandle;
      private string mConnectionString;
    
      public WorkflowLoader(string connectionString)
      {
       mConnectionString = connectionString;
       Open();
      }
    
      public WorkflowApplication CreateInstance(Activity activity, IDictionary<string,object> inputs)
      {
       //
       // if we dont have an instance store, then we have been disposed already
       //
       if (InstanceStore == null)
        throw new ObjectDisposedException("WorkflowLoader");
    
       WorkflowApplication instance = inputs == null ? new WorkflowApplication(activity) : new WorkflowApplication(activity, inputs);
       instance.InstanceStore = InstanceStore;
    
       return instance;
      }
    
      void Open()
      {
       this.InstanceStore = new SqlWorkflowInstanceStore(mConnectionString);
    
       CreateWorkflowOwnerCommand createWorkflowOwnerCommand = new CreateWorkflowOwnerCommand();
       mInstanceHandle = this.InstanceStore.CreateInstanceHandle();
    
       var view = this.InstanceStore.Execute(mInstanceHandle, createWorkflowOwnerCommand, TimeSpan.FromSeconds(30));
    
       InstanceStore.DefaultInstanceOwner = view.InstanceOwner;
      }
    
      #region IDisposable Members
    
      public void Dispose()
      {
       this.InstanceStore.Execute(mInstanceHandle, new DeleteWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
       mInstanceHandle.Free();
       InstanceStore = null;
      }
    
      #endregion
     }
    

    Friday, May 13, 2011 5:43 PM

Answers

  • Hi, David

    I checked your code, and all seems good. Since it happens for any WF. I doubt that there could be something wrong on your Sql Server. How about change a SQL server instance or recreate the WF4 persistence store.

    ->" As a side note, the same behavior occurs when starting a new instance as well"
    are you storing the xaml definition in database also. or how could the delay happens when a new instance starting. there is no persisted data in persistence store when a new instance is starting.

    Regards

    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Tuesday, May 24, 2011 8:29 AM
    Friday, May 20, 2011 2:54 AM

All replies

  • Could you also paste the "Loading" code here.
    Did you see any error message?
    Do you experience such a delay when loading any workflows? or just this one?

    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Tuesday, May 17, 2011 7:13 AM
  • No error message, and it happens on for any WF.  Here is the loading code:

       using (var loader = new WorkflowLoader(controlConnectionString))
       {
        var activity = workflowDefinition; 
        var workflowInstance = loader.CreateInstance(activity, null);
    
        workflowInstance.Load(workflowInstanceId);
    
        //.. other stuff not important
       }
    
    Where workflowDefinition is of type Activity loaded via Type.GetType.  When i break at .Load, and then step over it is when I see the 5-10 sec delay.  As a side note, the same behavior occurs when starting a new instance as well.  There is a 5-10 delay before the WF actually starts executing (this time via .Run())

    Tuesday, May 17, 2011 6:11 PM
  • Hi, David

    I checked your code, and all seems good. Since it happens for any WF. I doubt that there could be something wrong on your Sql Server. How about change a SQL server instance or recreate the WF4 persistence store.

    ->" As a side note, the same behavior occurs when starting a new instance as well"
    are you storing the xaml definition in database also. or how could the delay happens when a new instance starting. there is no persisted data in persistence store when a new instance is starting.

    Regards

    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Tuesday, May 24, 2011 8:29 AM
    Friday, May 20, 2011 2:54 AM