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();
}

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
Dwight6531