Why doesn't workflowInstance be loaded when the timer expired?

Hi all,

I'm developing a custom persistenceService which is inherited WorkflowPersistenceService.Following code is part of it. The workflowInstance can be unloaded when it is Idle,but the workflowInstance can't be loaded when the timer expired ,and the ReloadWorkflow(object id) method can't be called.Why it happens

protected override bool UnloadOnIdle(Activity activity)
{

return true;
}

protected override void SaveWorkflowInstanceState(Activity rootActivity, bool unlock)
{
// See when the next timer (Delay activity) for this workflow will expire
TimerEventSubscriptionCollection timers = (TimerEventSubscriptionCollection)rootActivity.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty);
TimerEventSubscription subscription = timers.Peek();
if (subscription != null)
{
// Set a system timer to automatically reload this workflow when it's next timer expires
TimerCallback callback = new TimerCallback(ReloadWorkflow);
TimeSpan timeDifference = subscription.ExpiresAt - DateTime.UtcNow;
Timer timer = new System.Threading.Timer(
callback,
subscription.WorkflowInstanceId,
timeDifference < TimeSpan.Zero TimeSpan.Zero : timeDifference,
new TimeSpan(-1));
}


// Save the workflow
Guid instanceId = (Guid)rootActivity.GetValue(Activity.ActivityContextGuidProperty);
sqlGenerator.SaveWorkflowInstanceState(instanceId, GetDefaultSerializedForm(rootActivity),
(int)GetWorkflowStatus(rootActivity), GetSuspendOrTerminateInfo(rootActivity),
subscription != null subscription.ExpiresAt : DateTime.MaxValue, GetIsBlocked(rootActivity) 1 : 0);
}

private void ReloadWorkflow(object id)
{
// Reload the workflow so that it will continue processing
this.Runtime.GetWorkflow((Guid)id).Load();
}



Answer this question

Why doesn't workflowInstance be loaded when the timer expired?

  • Mike Smith-Lonergan

    Have you set a breakpoint inside the if block that checks to see if the subscription is null to make sure that there are active timers If a handle external event activity is what is causing the workflow to become idle then there wouldn’t be a timer created. Are you sure that a delay is causing the workflow to go idle



  • Noah Falk - MSFT

    yes,i am sure that workflowInstance can be unloaded into database when the delay activity causing it to go idle,and the timer would be created.I have traced it and found that subscription.ExpiresAt was right,but the ReloadWorkflow method have not be called when the timer expired,and any matter has not all occurred.
  • Dwight6531

    Have you been able to resolve this problem Were you using the ManualWorkflowSchedulerService If so, there have been changes with the release version. Try setting UseActiveTimers to true on the ManualWorkflowSchedulerService.

  • Why doesn't workflowInstance be loaded when the timer expired?