Friday, June 02, 2006 5:27:50 AM (GMT Standard Time, UTC+00:00)
I've answered a bunch of questions about this lately so I thought I'd make a blog most to clarify what this method is all about.
WorkflowInstance.GetWorkflowDefinition returns a full-flegded instantiated Activity object based on what you've passed into WorkflowRuntime.CreateWorkflow. But it is *not* (let me repeat myself - *NOT*) the WorkflowInstance that you might execute. It is essentially a template of the Activity Type itself at the time of the call to CreateWorkflow.
It is used by the runtime as the template for various purposes, and can also be used by you in your Hosting layer as the type information about the workflow that you are currently executing.
But is is *not* (am I repeating myself?) the instance that is executing. This means you do *not* set property values on the instance returned from GetWorkflowDefintion. Any properties you set will not be reflected on the running workflow.
Ever set a breakpoint in your Root Activity's constructor? If you do - you'll see it called twice at the first execution of a workflow. This is because the Runtime calls it once to create the instance it is going to execute - and then creates another instance to keep around as the "template".
How can you use this? If you want to create WorkflowChanges - you'll use this defintion as the template that changes can be applied to (before you apply those changes to an active instance).
The fact that the GetWorkflowInstance activity is not your Activity that is executing is easily proved inside of the debugger. Set a break point inside of the Execute method of your Root Activity (if you don't override the Execute method - do it just for fun so you can set a breakpoint) - and then in the intermediate window type:
this == this.GetValue(Activity.WorkflowDefinitionProperty)
It will always return false (yes the WorkflowRuntime gets the WorkflowDefinition from a depedency property on the workflow itself - clever).
The right way to set properties on a WorkflowInstance is to pass a Dictionary as the second parameter to CreateWorkflow - and that will set properties on *that instance*. I hope this helps people to understand what GetWorkflowInstance is all about.
WF
Tracked by:
"Doug's Connected Applications Blog Report / June 3" (Clemens Vasters: Enterpris... [Trackback]
http://friends.newtelligence.net/clemensv/PermaLink,guid,6ce2b8fe-93fd-421c-a685... [Pingback]
"Tech Blog Report" (Gustavo Echeverry's Blog) [Trackback]
http://blogs.devdeo.com/gustavo.echeverry/PermaLink,guid,3c7a980d-0262-498f-acbe... [Pingback]