locked
WF4 / WorkflowApplication / TrackingParticipant: No Tracking inside of a "Sub-Workflow" RRS feed

  • Question

  • Hi,

    I run a Workflow "Workflow1" which contains some activities and calls a Workflow "Workflow2" among some WriteLine Activities:

    Diagrams of Workflow 1 & Workflow 2

    I run the Workflow via WorkflowApplication in my ConsoleApplication:

    using System;

    using System.Activities;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Workflows;

    namespace SimpleTrackingTest

    {

        class Program

        {

            static void Main(string[] args)

            {

                System.Console.WriteLine("Start Workflow 1");

                Workflow1 myWF = new Workflow1();

                WorkflowApplication wfApp = new WorkflowApplication(myWF);

                SimpleWorkflowTrackingParticipant trackingParticipant = new SimpleWorkflowTrackingParticipant();

                wfApp.Extensions.Add(trackingParticipant);

                wfApp.Run();

                System.Console.ReadKey();

            }

        }

    }

    In my simple Program above I also add my SimpleWorkflowTrackingParticipant as Workflow Extension. Here is my SimpleWorkflowTrackingParticipant:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Activities;

    using System.Activities.Tracking;

    namespace SimpleTrackingTest

    {

        public class SimpleWorkflowTrackingParticipant : TrackingParticipant

        {

            public SimpleWorkflowTrackingParticipant()

            {

                TrackingProfile trackingProfile = new TrackingProfile();

                trackingProfile.Queries.Add(new ActivityStateQuery

                {

                    ActivityName = "*",

                    States = { "*" },

                    Variables = { "*" },

                    Arguments = { "*" }

                });

                trackingProfile.Queries.Add(new WorkflowInstanceQuery

                {

                    States = { "*" },

                });

               

                this.TrackingProfile = trackingProfile;

            }

            protected override void Track(TrackingRecord record, TimeSpan timeout)

            {

                WorkflowInstanceRecord workflowInstanceRecord = record as WorkflowInstanceRecord;

                if (workflowInstanceRecord != null)

                {

                    System.Console.WriteLine("Workflow:" + workflowInstanceRecord.ActivityDefinitionId + " / State:" + workflowInstanceRecord.State);

                }

                ActivityStateRecord activityStateRecord = record as ActivityStateRecord;

                if (activityStateRecord != null)

                {

                    System.Console.WriteLine("Activity:" + activityStateRecord.Activity.Name + " / State:" + activityStateRecord.State);

                }

            }

        }

    }

    When I run my program, I get the following output:

    Start Workflow 1
    Workflow:Workflow1 / State:Started
    Activity:Workflow1 / State:Executing
    Activity:Sequence / State:Executing
    WF1.WriteLine1
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Assign / State:Executing
    Activity:Assign / State:Closed
    WF1.WriteLine2:12
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Workflow2 / State:Executing
    WF2.WriteLine1
    WF2.WriteLine2: 34
    Activity:Workflow2 / State:Closed
    WF1.WriteLine3
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Sequence / State:Closed
    Activity:Workflow1 / State:Closed
    Workflow:Workflow1 / State:Completed

    As the lines show, tracking (Track) is not called for the activities in Workflow2.

    I would like to know, how I can force the Workflow Runtime to call the Tracking Participant also for all subsequent activities called in Workflow2.

    I already lerned, that the extension is available to the activities in Workflow2 (so a custom activity could retrieve the Tracking Participant from the context of Workflow2). It just seems as if the Workflow Runtime does not call the Track method of the Tracking Participant.

    Thanks & Best Regards

    Stephan


    • Edited by Stephan .WF Thursday, September 13, 2012 11:44 AM
    Thursday, September 13, 2012 11:44 AM

Answers

  • Hi,

    after trying TraceTrackingParticipant (WF Trace Info 2 VS Debug Window) and ListTrackingParticipant from the Microsoft.Activities.Extensions Package (nuget link), I deleted the creation of a TrackingProfile in the constructor of my TrackingParticitpant:

            public SimpleWorkflowTrackingParticipant()
            {
                TrackingProfile trackingProfile = new TrackingProfile();
                // Just do not give a Tracking Profile
                this.TrackingProfile = null;
            }

    Afterwards, my TrackingParticipant got all desired TrackRecords...

    Start Workflow 1
    Workflow:Workflow1 / State:Started
    Activity:Workflow1 / State:Executing
    Activity:Sequence / State:Executing
    WF1.WriteLine1
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Assign / State:Executing
    Activity:Assign / State:Closed
    WF1.WriteLine2:12
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Workflow2 / State:Executing
    Activity:Sequence / State:Executing
    WF2.WriteLine1
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Assign / State:Executing
    Activity:Assign / State:Closed
    WF2.WriteLine2: 34
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Sequence / State:Closed
    Activity:Workflow2 / State:Closed
    WF1.WriteLine3
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Sequence / State:Closed
    Activity:Workflow1 / State:Closed
    Workflow:Workflow1 / State:Completed


    So it seems, that the TrackingProfile is not considered in Sub-Workflow-Execution, which I consider a bug. But I' m happy with this workaround. Thanks & Best Regards Stephan

    • Marked as answer by Stephan .WF Wednesday, September 26, 2012 4:15 PM
    Wednesday, September 26, 2012 4:15 PM

All replies

  • Hi Stephan,

    I think this is an issue .. which has been fixed in Microsoft.Activities v1.8.3 now available on NuGet

    Please go through these links as weel to get better understanding.

    http://wf.codeplex.com/workitem/8595

    http://blogs.msdn.com/b/rjacobs/archive/2011/05/26/tracking-child-workflow-with-invokeworkflow.aspx

    Thanks,

    Madhur


    MB

    Friday, September 14, 2012 11:02 AM
  • Hi Madhur,

    thanks a lot for the links, which I found very interesting. I installed the package via NuGet.

    I tried to execute my example with both WorkflowInvoker & WorkflowApplication (I need to use WorkflowApplication in my actual project).

    When I execute my example using the TraceTrackingParticipant, Tracking includes the activities of the Sub-Workflow. However, with my own TrackingParticipant this is still not working. This is independent of the used WF runtime (Workflow-Invoker/Application).

    So I'm wondering if it is an issue of my TrackingParticipant / TrackingProfile or if it is an issue in WF. I need help:-)

    Thanks & Best Regards

    Stephan

    Friday, September 14, 2012 2:57 PM
  • Hi,

    after trying TraceTrackingParticipant (WF Trace Info 2 VS Debug Window) and ListTrackingParticipant from the Microsoft.Activities.Extensions Package (nuget link), I deleted the creation of a TrackingProfile in the constructor of my TrackingParticitpant:

            public SimpleWorkflowTrackingParticipant()
            {
                TrackingProfile trackingProfile = new TrackingProfile();
                // Just do not give a Tracking Profile
                this.TrackingProfile = null;
            }

    Afterwards, my TrackingParticipant got all desired TrackRecords...

    Start Workflow 1
    Workflow:Workflow1 / State:Started
    Activity:Workflow1 / State:Executing
    Activity:Sequence / State:Executing
    WF1.WriteLine1
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Assign / State:Executing
    Activity:Assign / State:Closed
    WF1.WriteLine2:12
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Workflow2 / State:Executing
    Activity:Sequence / State:Executing
    WF2.WriteLine1
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Assign / State:Executing
    Activity:Assign / State:Closed
    WF2.WriteLine2: 34
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Sequence / State:Closed
    Activity:Workflow2 / State:Closed
    WF1.WriteLine3
    Activity:WriteLine / State:Executing
    Activity:WriteLine / State:Closed
    Activity:Sequence / State:Closed
    Activity:Workflow1 / State:Closed
    Workflow:Workflow1 / State:Completed


    So it seems, that the TrackingProfile is not considered in Sub-Workflow-Execution, which I consider a bug. But I' m happy with this workaround. Thanks & Best Regards Stephan

    • Marked as answer by Stephan .WF Wednesday, September 26, 2012 4:15 PM
    Wednesday, September 26, 2012 4:15 PM
  • Hi Stefan,

    I saw your post and felt you would be able to solve my problem, I'm sorry if i have posted at a wrong place, but your post is almost near to my problem area! :) Problem: I was not able to add a workflow as an activity into a main workflow. Would you please help me in this regard, currently I was trying to add a workflow to a main workflow using an activity where physical file path of the sub workflow is given as an input, but it's not working! Any of your help would be appreciated.

    Thanks,

    Jeenendra


    • Edited by Jeenendra Friday, October 26, 2012 11:20 AM
    Friday, October 26, 2012 11:14 AM
  • Hi Jeenendra,

    I'm not sure if I understood you right. When you create a workflow, it should be shown in the Toolbox, so that you can easily drop it into another workflow. (This is very simple and I think it is not what you really ment. But this is my simple sub-workflow scenario where I encountered the problems with tracking, indeed.)

    Workflow as Activity and access via Toolbox

    If you want to invoke a workflow from a file, did you consider this article? :

    http://code.msdn.microsoft.com/WF4-How-To-Invoke-A-Child-86cc6d31

    If this does not help, you should provide details and maybe coding so that it is possible to understand what your issue actually is.

    HTH

    Stephan

    Monday, October 29, 2012 11:00 AM