Workflow Instances persisted by different hosts

Hi,

For example, I have 3 Winform Workflow host applications (with 3 different workflows also). They all using the SqlPersistenceService.

Now I want to add a function to each of them to check the persisted workflow with the routine like this

Dim instances As IEnumerable(Of SqlPersistenceWorkflowInstanceDescription)
instances = PersistenceService.GetAllWorkflows
Dim instance As SqlPersistenceWorkflowInstanceDescription

For Each instance In instances
System.Windows.Forms.MessageBox.Show(instance.WorkflowInstanceId.ToString)

Next

Everything work fine. But if I added the the to check the Status of the workflow (with StateMachineInstance) or try to load the workflow with :

Dim Wfi As WorkflowInstance
Wfi = WorkflowRuntime.GetWorkflow(instance.WorkflowInstanceId)

Error will be occur on those workflows instances which not related to the host (probably because of no reference to them).

Any my questions are:

1) Is that we need some sort of checking / filter / query to find out those related instances only (as we can't reference to all workflows.)

2) How can we have Workflow Monitor which can show all kinds of persisted workflow instances (of different kinds of workflow) and their Status

Please advise.

Andy Ho




Answer this question

Workflow Instances persisted by different hosts

  • KhRo

    Joel,

    If I want to develop a generic Workflow Monitor (WinForm) to monitor all the workflow instances generated by difference hosts, does it mean the Winform need to reference to all available workflows If yes, then every time we add a need workflow, we need to recompile the Workflow Monitor again

    Andy


  • rv_saraswathi

    Khalid,

    Any code sample which can list all the outstanding (not yet completed) workflow instances (no matter what status they are)

    Thanks in advance

    Andy


  • SBoswood

    Richard,

    May I know if not using the Persistence Service, how do we know how many workflow instances are currently outstanding (not completed)

    Right now what I'm using is by checking the persisted workflow instances.

    Please advise.

    Andy Ho


  • papadi

    I've done this particular example before and had no trouble reconstituting the workflow. When you get your Wfi instance, do you call Wfi.Load() immediately after calling GetWorkflow This is required if the host didn't originate the workflow because it has to retrieve it from persistence, which won't be done until you call Load() [at least, that's how it worked in the May CTP]


  • keewest

    Khalid Aggag,

    Thanks for your code. It works only if I specify the workflow type. If I comment the line:

    options.WorkflowType = typeof(SimpleWorkflow);

    the code will get an " Could not load file or assembly " error at the workflow instance(s) which not referenced to the host. Therefore I can't have a generic workflow monitor which can list all the instances created by different hosts.

    Also is that only one workflow type can be specified Can I get the workflow of more than one type

    Andy Ho


  • dork

    No, you don’t need to recompile your generic Workflow Monitor. All you
    need is make available the assembly that contains the new workflow type
    to the monitor, either by placing it in the same directory as the
    monitor exe or by installing it directly in the GAC.


  • Deza

    Hello Andy,
    From any program that can access the oob sql tracking
    database and your workflow types, you can run the below sample usage
    example to obtain all running (not yet completed nor terminated)
    instances in the tracking database.

    SqlTrackingQuery sqlTrackingQuery = new
    SqlTrackingQuery(connectionString); //Add a connection string to your
    tracking database
    SqlTrackingQueryOptions options = new
    SqlTrackingQueryOptions();
    options.WorkflowStatus = WorkflowStatus.Running;
    options.WorkflowType = typeof(SimpleWorkflow); //Add the
    type of the workflow you are interested in, or comment out to retrieve
    all workflow instances
    IList<SqlTrackingWorkflowInstance> list =
    sqlTrackingQuery.GetWorkflows(options);
    foreach (SqlTrackingWorkflowInstance
    sqlTrackingWorkflowInstance in list)
    {

    Console.WriteLine(sqlTrackingWorkflowInstance.WorkflowInstanceId + " " +
    sqlTrackingWorkflowInstance.WorkflowType.Name + " "
    +

    sqlTrackingWorkflowInstance.WorkflowDefinition.Name);
    }

    I hope this helps.


  • Thomas LEBRUN

    The persistence service is not the right service to be using. Generally, when you get a workflow from a peristence service, you are doing to it perform activity on it (start it, send an event, etc). Plus, if the workflow is already executing (on the existing host or another host using the same persistence database), it's going to be locked.

    Where you want to get your workflow information is from a tracking service. Check out the example of the Workflow Tracking Monitor.

  • Felipe Heidrich

    If you are using the oob sql Tracking service you could query the
    tracking database via the SqlTrackingQuery class, just specify the
    workflow types and statuses you want to retrieve in your query, you
    could event query the sql tracking database directly for greater
    flexibility, since the database schema is publicly exposed. If you use a
    custom sql tracking service, then it depends on what the service did
    with the tracking events, to get this piece of information.


  • hellomahesh

    Hello Andy,
    Using the Tracking service you can track and monitor every state of the
    workflow during its life cycle. This is what the tracing feature in WF
    is created for. The persistence database serves another purpose than
    monitoring the state of a workflow. You can use the Tracking service to
    achieve your goal of finding the currently outstanding workflow
    instances.


  • rxg

    Joel,

    When query the outstanding workflow, there is an option to set the flow type:

    options.WorkflowType = typeof(SimpleWorkflow);

    What if I want to query more than one type How the code will be

    Andy Ho


  • ITfJ

    I believe Andy's question was : How do you iterate the list of all workflows in the system, persisted or otherwise, without actually using the Persistence service I think his question stems from the idea that tracking gives you detail on a single workflow, but persistence is what tells you the list of all workflows in the system... unless Tracking can do that too and I just missed the method that does it

  • DuncanP

    You don't need to specify a workflow type when you query. However you do need to have all of the types that you run in your system available on the machine where you run the query. This applies to workflow types, activity types and the types of any data members extracted from the workflow.

    Thanks,

    Joel West

    MSFTE - SDE in WF runtime and hosting

    This posting is provided "AS IS" with no warranties, and confers no rights


  • Workflow Instances persisted by different hosts