Significance of Unlock flag in 'WorkflowPersistenceService' ?
Hi,
I'm currently analysing the use of 'unlock' flag provided in the 'WorkflowPersistenceService' class.As I would like to write a 'Custom' Persistence service.
protectedoverridevoid SaveWorkflowInstanceState(System.Workflow.ComponentModel.ActivityrootActivity,boolunlock)
Observations:
1)I always see that unlock is set to true whenever the above method is called to persist an instance.
2)Also the SQL stored proc's provided in the labs handle two cases for 'Unlocked' =0 &'Unlocked'=1...Why is it so?
3)As far as my understanding goes this flag means that an instance is being unloaded from the memory and is hence unlocked,so the flag is always set as 'true'....with this assumption why are the procedures handling two scenarios.
Thanks in advance....
Regards,
[1361 byte] By [
crp2k4] at [2007-12-24]
There are definitely conditions when this flag will be false. You should handle both cases in your persistence service. For example say a persist event occurs because an instance has become idle. The WF runtime will ask the persistence service (via the UnloadOnIdle method) if the instance should be unloaded. If it returns false the persist will still occur but unlocked will be false because the instance is not being removed from memory.
Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting
This posting is provided "AS IS" with no warranties, and confers no rights
When unlocked = true it means that the WF runtime is release the instance from memory. It will not do any further work for the instance unless it is reload into that WF runtime. Basically this flag is for a multi-host scenario where you have more than 1 machine accessing the persistence store. You don't ever want the instance loaded on more than 1 host machine at a time. True means that the machine that currently has the instance is releasing it. It is then OK to load the instance on a different machine.
Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting
This posting is provided "AS IS" with no warranties, and confers no rights
Actually I'm trying to develop a persistence service running in a that is hosted in a web-service,and we could have multiple wfRuntimes so another question is how can we handle 'optimistic locking'.I found that you could do it in the folllowing way..but I have a doubt
1)Lets say I have a 'CreateXYZ' activity that stores some details to the database.Next a 'UpdateXYZ' activity would update the same details,Let ssay the insatnce is loaded and update operation is executing.
2)At the same time another runtime loads the same instance and tries to update it but the optimistic check would fail.Hence only the runtime that executed the instance (the one which successfully updated ) should be allowed to persist.
Now the question is when the 'SaveInstanceState' method of the persistence service is called how could I know whether the wf instance is the one that successfully carried out the update op. or not? Can you direct me to a better approach...I want to awoid using the 'ownershipTimeOut' flag.
Thanks & Regards
>> 1)Lets say I have a 'CreateXYZ' activity that stores some details to the database.Next a 'UpdateXYZ' activity would update the same details,Let ssay the insatnce is loaded and update operation is executing.
>> 2)At the same time another runtime loads the same instance and tries to update it but the optimistic check would fail.Hence only the runtime that executed the instance (the one which successfully updated ) should be allowed to persist.
You should never have more than 1 workflow runtime load the same instance at the same time. This is what the locking functionality on the WorkflowPersistenceService is intended to resolve.
Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting
This posting is provided "AS IS" with no warranties, and confers no rights