locked
Searching for delayed workflow instances occurres TimeoutException - always RRS feed

  • Question

  • Hi,

    we would like to continue delayed workflow instances. For that we use the following code:

    Dim store = New SqlWorkflowInstanceStore(...)
    
    handle = store.CreateInstanceHandle()
    Dim view = store.Execute(handle, New CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(1))
    
    store.DefaultInstanceOwner = view.InstanceOwner
    
    Dim events = store.WaitForEvents(handle, TimeSpan.FromSeconds(10))
    
    For Each currentEvent As InstancePersistenceEvent In events
       If currentEvent = HasRunnableWorkflowEvent.Value Then
    ...
          Exit For
       End If
    Next

    But it doesn't work. The line with 'WaitForEvents' produces always a TimeoutException, not dependend if there are delayed workflow instances in the store or not. So it looks that is always produces the exception.

    Do we the wrong way to execute delayed workflows or what is wrong.

    Best regards,

    Torsten

    Wednesday, July 22, 2015 11:54 AM

Answers

  • You can first query the store if there are any instances that are ready to run to make this more efficient. The store API for this is WaitForEvents.

      MyInstanceStore store = new MyInstanceStore();
                    InstanceHandle handle = store.CreateInstanceHandle(null);
                    InstanceOwner owner = store.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.MaxValue).InstanceOwner;                
    
                    store.DefaultInstanceOwner = owner;                
    
                    bool hasRunnableWorkflows = false;
                    
                    foreach (InstancePersistenceEvent currentEvent in store.WaitForEvents(handle, TimeSpan.Zero))
                    {
                        if (currentEvent == HasRunnableWorkflowEvent.Value)
                        {
                            hasRunnableWorkflows = true;
                            break;
                        }
                    }
    
                    if (hasRunnableWorkflows)
                    {
                        Console.WriteLine("Found runnable workflows");
                        
                        WorkflowApplication app = new WorkflowApplication( .... );
                        app.InstanceStore = store;
                        app.LoadRunnableInstance();                                       
                        app.Run();
                    }
                    else
                    {
                        Console.WriteLine("Did not find runnable workflows");
                    }

    For more information, please refer to the document:

    https://adrianot75.wordpress.com/2010/11/04/wf4-persisnce-delay-and-execution-resume/

                  
    • Marked as answer by Pengzhen Song Thursday, August 13, 2015 5:51 AM
    Tuesday, July 28, 2015 12:26 PM