locked
Workflow Foundation 4.0 Persistance Issue. RRS feed

  • Question

  • I am trying to get the list of all the workflow instances that have been suspended due to unhandled exception.

    I am looking at the [System.Activities.DurableInstancing].InstancesTable . the value of the instance is not being updated when the instance is terminated or workflow is completed. but the instance record is created.

    given below is my instance persistance code.

         

     SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=[machineName];Initial Catalog=[DatabaseName];Integrated Security=True");
          instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;
          instanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteNothing;
          InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(1));
          instanceStore.DefaultInstanceOwner = view.InstanceOwner;
          WorkflowApplication newApp = CreateWorkflow(instanceStore);

    This is my workflow completed code

         

     static void WfCompleted(WorkflowApplicationCompletedEventArgs e)
        {
          if (e.CompletionState == ActivityInstanceState.Faulted)
          {
            Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
            Console.WriteLine("Exception: {0}\n{1}", e.TerminationException.GetType().FullName, e.TerminationException.Message);
            Console.ReadLine();
          }
          else if (e.CompletionState == ActivityInstanceState.Canceled)
          {
            Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
            Console.ReadLine();
          }
          if (e.CompletionState == ActivityInstanceState.Closed)
          {
            Console.WriteLine("Workflow {0} Closed.", e.InstanceId);
            Console.ReadLine();
          }
          if (e.CompletionState == ActivityInstanceState.Executing)
          {
            Console.WriteLine("Workflow {0} Executing.", e.InstanceId);
            Console.ReadLine();
          }
          else
          {
            Console.WriteLine("Workflow {0} Completed.", e.InstanceId);
            DateTime finish = DateTime.Now;
            Console.WriteLine("Finishing: " + finish.ToString());
            Console.ReadLine();
          }
        }

    This is my UnhandledExceptionActionException code

         

     static UnhandledExceptionAction WfUnhandledException(WorkflowApplicationUnhandledExceptionEventArgs e)
        {
          // Display the unhandled exception.
          // Instruct the runtime to terminate the workflow.
          // Other choices are Abort and Cancel
          Console.WriteLine("Workflow {0} UnhandledException.", e.UnhandledException.Message);
          return UnhandledExceptionAction.Abort;
        }

     

    the events are getting triggered accordingly but the database values are not being updated..

    FYI.  when the workflow is in idle state persistence takes place.. but how to will the database get updated when the workflow is completed or gets suspended..

     

    Wednesday, October 13, 2010 2:25 AM

Answers

  • Do you mean updating the database to have the instance set to Closed state?

    I don't see anything obviously wrong with your code posted, and if you try the sample WF > Basic > Persistence > InstancePersistence (download sample from here, and readme is here) and it is able to update the record to Closed state when the workflow completes with instanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteNothing;

    Would you give the sample a try, and see if there's any differences between your way and the way the sample does it?


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Andrew_Zhu Wednesday, October 20, 2010 6:49 AM
    Monday, October 18, 2010 4:01 PM

All replies

  • Hi,

    ->"the events are getting triggered accordingly but the database values are not being updated.."
    Which value you want to update? 

    ->"but how to will the database get updated when the workflow is completed or gets suspended.."
    Do you have a reason to do so? if a workflow is completed, you can no long resume the persisted data. If you want to recording the exception info. Tracking would be a good choice. or you can just write this kind of info into another database or file as you wish.

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    Monday, October 18, 2010 7:14 AM
  • Do you mean updating the database to have the instance set to Closed state?

    I don't see anything obviously wrong with your code posted, and if you try the sample WF > Basic > Persistence > InstancePersistence (download sample from here, and readme is here) and it is able to update the record to Closed state when the workflow completes with instanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteNothing;

    Would you give the sample a try, and see if there's any differences between your way and the way the sample does it?


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Andrew_Zhu Wednesday, October 20, 2010 6:49 AM
    Monday, October 18, 2010 4:01 PM