persistent services and state machines questions.
- Hello,
I have a few newbie questions on workflow, if anyone is kind enough to help me :)
1.) I have a state machine workflow which i need to persist after each state, and not wait for it to become IDLE. Furthermore, i need to trigger the persistence service from a "CodeActivity". Is this possible ? I feel this is not the right approach.
2.) This state machine controls a flow hosted in a silverlight+asp application. Most of it's actions are triggered as a result of user interaction.
Each user action should trigger the transition to a new state, so i was thinking to : a.) persist the workflow when the state ends, and b.) reload it when user triggers action.
Question : Giving the fact that, on a new user request, i don't have access to the WorkflowRuntime that originally created the workflow, is it possible to load it from database, and then continue the processing in another runtime ? What happens if I would use the "Unload on IDLE" feature, and, on a new
user request, i don't know if the workflow had become idle or not ? Is there some way to scan for all workflows with given guid, to see if they're active, without having the original runtime instance ?
There is something i'm missing here about the runtime functionality, that i'm missing.
3.) I created a custom persistent service, derived from the Microsoft sample "CustomPersistenceService", which basically stores data to a file.
I copied the sample, and i modified the functions which write/read to/from file, to do the same thing to/from a field in my database.
Question : does this seems right ? It hardly seems so. I looked in the database schema needed for built in SqlPersistentService, and it looked a bit more complex, but given the fact that the microsoft sample only used the files to store a byte[], this should theoretically work.
4.) I used the Microsoft scripts to create database for use with SqlPersistentService, out of curiosity, and looked at the fields in it. I noticed that fields
designed to store the workflow data were "image", with the length of 16. This made me curious : is 16 bytes all wwf needs to store it's state ? Seems very small.
Thanks !!
Andrei
Answers
Hello,
I have a few newbie questions on workflow, if anyone is kind enough to help me :)
1.) I have a state machine workflow which i need to persist after each state, and not wait for it to become IDLE. Furthermore, i need to trigger the persistence service from a "CodeActivity". Is this possible ? I feel this is not the right approach.Good call — it probably isn't a good approach. As for the need to trigger persistence from a CodeActivity; well actually there is a really solid alternative: Custom Activities.
Some devs (including those I work with) initially had an over-propensity to leverage CodeActivities for everything when they were new to WF. I suppose they saw CustomActivities as too much overhead; but often it makes a lot of sense to use CustomActivities to contain logic. It is also important to keep in mind that you'll have a lot easier time converting 3.5 workflows to 4.0 since CodeActivities are one of the items on the deprecation list...
CustomActivities also answer your persistence dilemma nicely. Simply decorate your CustomActivity class with the "PersistOnClose()" attribute and your workflow will be serialized into the InstanceState table within your database; ready to be re-hydrated later.2.) This state machine controls a flow hosted in a silverlight+asp application. Most of it's actions are triggered as a result of user interaction.
Each user action should trigger the transition to a new state, so i was thinking to : a.) persist the workflow when the state ends, and b.) reload it when user triggers action.
Question : Giving the fact that, on a new user request, i don't have access to the WorkflowRuntime that originally created the workflow, is it possible to load it from database, and then continue the processing in another runtime ? What happens if I would use the "Unload on IDLE" feature, and, on a new
user request, i don't know if the workflow had become idle or not ? Is there some way to scan for all workflows with given guid, to see if they're active, without having the original runtime instance ?
There is something i'm missing here about the runtime functionality, that i'm missing.
It's a bit of a point of contention with me philosophically, but actually the recommended approach is to use human-initiated events to guide all state transition so you're on solid ground there. But you can persist your workflow whenever you like using PersistOnClose() in a CustomActivity — and I've found this the best approach. Trapping idle state seems a bit cumbersome (although certainly do-aboe) for almost every scenario I've encountered. And the Unload() method, while also valid, is only available from the workflow instance - which you can't call from within an activity that's already being hosted by the workflow you want to unload (for obvious reasons).
You could scan for all workflows to get data (including their GUIDs) using the TrackingService. But I haven't found the need to use the TrackingService for this purpose so far since I store the GUIDs alongside other data that I need to associate them with.3.) I created a custom persistent service, derived from the Microsoft sample "CustomPersistenceService", which basically stores data to a file.
Yeah regarding the column length of 16...I'm gonna hazard a guess that's not on the same scale as that used to reflect the number of places in an array of chars. For image, it's a set value....and the size is the same for every image type, which is at least 10Kb (see SQL Books Online documentation for more info). Space has been quite adequate for the workflows I've created, one of which is getting to be a fair size....
I copied the sample, and i modified the functions which write/read to/from file, to do the same thing to/from a field in my database.
Question : does this seems right ? It hardly seems so. I looked in the database schema needed for built in SqlPersistentService, and it looked a bit more complex, but given the fact that the microsoft sample only used the files to store a byte[], this should theoretically work.
4.) I used the Microsoft scripts to create database for use with SqlPersistentService, out of curiosity, and looked at the fields in it. I noticed that fields
designed to store the workflow data were "image", with the length of 16. This made me curious : is 16 bytes all wwf needs to store it's state ? Seems very small.
Thanks !!
Andrei
Hope those answers proved somewhat helpful. Good luck!
Ross is a .NET developer based in Gatineau, Québec (Canada), working with the Government of Canada.- Proposed As Answer byRoss Holder Friday, October 30, 2009 8:15 PM
- Marked As Answer byjohnny_r3d Friday, October 30, 2009 10:33 PM
All Replies
Hello,
I have a few newbie questions on workflow, if anyone is kind enough to help me :)
1.) I have a state machine workflow which i need to persist after each state, and not wait for it to become IDLE. Furthermore, i need to trigger the persistence service from a "CodeActivity". Is this possible ? I feel this is not the right approach.Good call — it probably isn't a good approach. As for the need to trigger persistence from a CodeActivity; well actually there is a really solid alternative: Custom Activities.
Some devs (including those I work with) initially had an over-propensity to leverage CodeActivities for everything when they were new to WF. I suppose they saw CustomActivities as too much overhead; but often it makes a lot of sense to use CustomActivities to contain logic. It is also important to keep in mind that you'll have a lot easier time converting 3.5 workflows to 4.0 since CodeActivities are one of the items on the deprecation list...
CustomActivities also answer your persistence dilemma nicely. Simply decorate your CustomActivity class with the "PersistOnClose()" attribute and your workflow will be serialized into the InstanceState table within your database; ready to be re-hydrated later.2.) This state machine controls a flow hosted in a silverlight+asp application. Most of it's actions are triggered as a result of user interaction.
Each user action should trigger the transition to a new state, so i was thinking to : a.) persist the workflow when the state ends, and b.) reload it when user triggers action.
Question : Giving the fact that, on a new user request, i don't have access to the WorkflowRuntime that originally created the workflow, is it possible to load it from database, and then continue the processing in another runtime ? What happens if I would use the "Unload on IDLE" feature, and, on a new
user request, i don't know if the workflow had become idle or not ? Is there some way to scan for all workflows with given guid, to see if they're active, without having the original runtime instance ?
There is something i'm missing here about the runtime functionality, that i'm missing.
It's a bit of a point of contention with me philosophically, but actually the recommended approach is to use human-initiated events to guide all state transition so you're on solid ground there. But you can persist your workflow whenever you like using PersistOnClose() in a CustomActivity — and I've found this the best approach. Trapping idle state seems a bit cumbersome (although certainly do-aboe) for almost every scenario I've encountered. And the Unload() method, while also valid, is only available from the workflow instance - which you can't call from within an activity that's already being hosted by the workflow you want to unload (for obvious reasons).
You could scan for all workflows to get data (including their GUIDs) using the TrackingService. But I haven't found the need to use the TrackingService for this purpose so far since I store the GUIDs alongside other data that I need to associate them with.3.) I created a custom persistent service, derived from the Microsoft sample "CustomPersistenceService", which basically stores data to a file.
Yeah regarding the column length of 16...I'm gonna hazard a guess that's not on the same scale as that used to reflect the number of places in an array of chars. For image, it's a set value....and the size is the same for every image type, which is at least 10Kb (see SQL Books Online documentation for more info). Space has been quite adequate for the workflows I've created, one of which is getting to be a fair size....
I copied the sample, and i modified the functions which write/read to/from file, to do the same thing to/from a field in my database.
Question : does this seems right ? It hardly seems so. I looked in the database schema needed for built in SqlPersistentService, and it looked a bit more complex, but given the fact that the microsoft sample only used the files to store a byte[], this should theoretically work.
4.) I used the Microsoft scripts to create database for use with SqlPersistentService, out of curiosity, and looked at the fields in it. I noticed that fields
designed to store the workflow data were "image", with the length of 16. This made me curious : is 16 bytes all wwf needs to store it's state ? Seems very small.
Thanks !!
Andrei
Hope those answers proved somewhat helpful. Good luck!
Ross is a .NET developer based in Gatineau, Québec (Canada), working with the Government of Canada.- Proposed As Answer byRoss Holder Friday, October 30, 2009 8:15 PM
- Marked As Answer byjohnny_r3d Friday, October 30, 2009 10:33 PM


