|
|
 |
Author |
Message |
Amanda Jamin

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
I am trying to get the workflow instance id of the executing workflow so that I can send it to my declared events. I have tried this.WorkflowInstanceId and WorkflowEnvironment.WorkflowInstanceId but when I get to firing the event I get an exception that says that the event could not be delivered. The inner exception is "Instance operation is not valid on workflow runtime thread"
Any suggestions
Amanda
Software Development for Windows Vista2
|
|
|
|
 |
Jon Flanders

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
Amanda - you (as the "host") have to keep track of this in someway. You can certainly find out what workflows are executing by using WorkflowRuntime.GetLoadedWorkflows
|
|
|
|
 |
Amanda Jamin

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
Is there no way then for the EventDriven activity of a state based workflow to handle an event internally raised from the workflow
What I have right now is a state based workflow which at some state executes an external sequential workflow. When it creates this sequential workflow, it subscribes to the runtime's (obtained via a WorkflowHostingService service) workflow completed event. When this event is fired, it checks to see if the InstanceId of the event matches that of the sequential workflow it just executed. If it matches, then it fires another event. It is this second event that my workflow state is listening for (and when it receives it, it should transition to the next state). This event though, as it extends ExternalDataEventArgs needs an InstanceId.
Is there a better way of doing this
Thanks.
Amanda
|
|
|
|
 |
Jon Flanders

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
If I understand what you are doing correctly - you are trying to execute a sequential workflow and then have it fire an event to another workflow. What you want to do is pass the guid of the statemachineworkflow as a parameter to the sequential workflow - and extract it from the OutputParameters property of WorkflowCompletedEventArgs.
I am pretty sure though you don't want to this this way. You don't want a statemachineworkflow subscribing to an event of the WorkflowRuntime. You can implement this all using a Host level service.
|
|
|
|
 |
Amanda Jamin

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
How would you implement this as a Host level service The host
itself does not know about the sequential workflow. I am open to
all suggestions, I just don't understand how I would go about
implementing this as a service. Would my service contain all the
events, or what
Thanks,
Amanda
|
|
|
|
 |
Matt Milner - Pluralsight

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
- On your sequential workflow, declare a public property for a workflow instance id.
- In the state machine workflow, use the InvokeWorkflow activity to start your sequential workflow and then move to a state where you will wait for the response (i.e. you have a HandleExternalEvent activity - see the next step).
- Define a local service interface with an event that signals the sequential workflow is done.
- In your host code or the same local service as the previous step (this is a better option) register a handler for the workflow completed event.
- In the handler for the completed event, use the event arguments to get the output parameters from the sequential workflow and get the instance ID parameter that points to the state machine workflow (this is the property you created in step 1).
- Now, raise the event on the local service interface, making sure to use the state machine instance ID so the event gets routed to the correct instance.
- The event handler in your state machine should take over and you'll know the sequential workflow is completed.
Matt
|
|
|
|
 |
Amanda Jamin

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
Doesn't that solution require me to be able to get the InstanceId of
the State Machine workflow from within itself Or did I miss a step
Amanda
|
|
|
|
 |
Jon Flanders

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
|
|
 |
Amanda Jamin

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
When I open the project it cannot find WorkflowProject4, which I assume as it cannot find Workflow2 is the project that holds the second workflow.
|
|
|
|
 |
Jon Flanders

|
Posted: Windows Workflow Foundation, WorkflowInstanceID |
Top |
Sorry - I've uploaded the repaired zip file.
|
|
|
|
 |
|
|