locked
When are tracking records emitted? RRS feed

  • Question

  • It seems like the tracking records relating to the execution of an activity are emitted *after* the activity has completed execution rather than during the activity execution. i.e. my CustomTrackingParticipant receives the Started, Executing, Completed and Closed records at the same time, even though the EventTime in each record is different. 

    Can someone confirm whether this is expected behaviour?

    The reason I'm interested in this is that I want to report progress during a long-running (i.e. CPU-intensive, rather than waiting for external input) activity, so I tried emitting custom tracking records as follows:

     

     

    public sealed class ProgressActivity : CodeActivity
    {
    	protected override void Execute(CodeActivityContext context)
    	{
    		for (var i = 0; i <= 10; i++)
    		{
    			var customTrackingRecord = new CustomTrackingRecord("Progress")
    				{
    					Data = { { "Progress", i * 10.0 } }
    				};
    
    			context.Track(customTrackingRecord);
    			Thread.Sleep(1000); // Some expensive calc goes here
    		}
    	}
    }
    

     

    However, when I run this activity I get all the custom tracking records together with the standard tracking records *after* the activity has completed.

    Can anyone explain what is going on? Failing that, can anyone suggest where else I can find information on this? I really need to figure out what is going on.

     

    Wednesday, March 16, 2011 3:45 PM

Answers

  • Thanks Andrew. If I end up writing my own monitoring extension I lose the ability to track built in activities because I won't be able to add the necessary calls in the Execute method. 

    I've looked further into the behaviour of the Delay activity and noticed that the "Executing" tracking record is emitted when the bookmark causes the workflow to become idle. I suspect that if I have an activity that emits custom records and then creates a bookmark, those custom records will be emitted at that point. So I'm wondering if I could do anything via creating/resuming bookmarks to force the progress tracking records to be emitted at the appropriate time?

     

    • Marked as answer by drakc Thursday, April 7, 2011 11:06 AM
    Tuesday, March 22, 2011 12:00 PM

All replies

  • Bump. Can anyone suggest where else I should look for information on this? 
    Thursday, March 17, 2011 5:00 PM
  • Yeah, I don't think is going to be a good approach. I can review and see exactly what is happening with the tracking records but I don't think they are going to be as immediate as you require. What you could do in a case like that is create a WorkflowExtension and you can call through that and notify the host of the progress of your intensive cpu processing. And it if is really intensive and long running, I would move it out of the workflow thread and into a host thread, for example by using an AsyncActivity. Or if it is really long running, then you could use an extension to signal the host to start the long running work and then create a bookmark and wait, and then the host could resume the bookmark. if it is only a few seconds or so of processing and you don't want/need to persist the workflow during that interval than using an AsyncActivity is the way to go. You can then report the status of the long running intensive processing from the other thread. I need to check to see if you can still use an extension to report that progress or if you would need to find another mechanism.

    For an example of a custom workflow extension, see http://blogs.msdn.com/b/tilovell/archive/2011/02/26/wf4-workflow-4-0-hosting-extensions-redux.aspx

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Friday, March 18, 2011 10:22 PM
  • Thanks Steve. I have put together a prototype that uses an extension to report progress and it works as expected. However, the reason I was trying to use a custom tracking record was because I was combining it with the visual workflow tracking example to show which activity is executing. I was hoping to be able to combine it with a progress bar adornment to show progress for long running activities.

    If tracking records are really emitted after the activity has completed, then the logic in the visual workflow tracking sample is flawed because the highlighting is always out of step: it highlights the completed activity, not the currently executing one. I find it hard to believe that there is such a big limitation with the tracking mechanism - much more likely is that there is something I have done wrong that causes this odd behaviour. Do you have any idea where I've gone wrong?

     

     

    Sunday, March 20, 2011 7:24 PM
  • I see what you're saying. Let me check into that sample and confirm the timing of the tracking and I will report back.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Monday, March 21, 2011 1:22 PM
  • A quick update. I've discovered that the Delay activity does emit tracking records during execution. When a sequence of these activities are placed in a flow chart the highlighting in the visual workflow tracking sample works correctly.

    So, something about the way I've implemented the ProgressActivity is causing the problem. I tried viewing the Delay activity source via Reflector, but it is far more complex than I expected and I didn't come away any wiser!

    Monday, March 21, 2011 5:00 PM
  • Hi, drakc

    ->"So, something about the way I've implemented the ProgressActivity is causing the problem. I tried viewing the Delay activity source via Reflector, but it is far more complex than I expected and I didn't come away any wiser!"

    Usually,the execution timespan of a non-bookmark activity is pretty short. and it is no need to track these activities visually. such as WriteLine, Assign activities.

    As far as I know, the bookmark activity's idle event will be emited by Tracking Participant, and we can see the visuall state of a bookmark activity. Delay activity is actually a bookmark activity which can resume execution by a timer.

    If you really want a real time visual tracking. You may want to consider creating a WF visual monitoring extension. WF extension can be called in the Execute method of an activity.

    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Tuesday, March 22, 2011 3:23 AM
  • Thanks Andrew. If I end up writing my own monitoring extension I lose the ability to track built in activities because I won't be able to add the necessary calls in the Execute method. 

    I've looked further into the behaviour of the Delay activity and noticed that the "Executing" tracking record is emitted when the bookmark causes the workflow to become idle. I suspect that if I have an activity that emits custom records and then creates a bookmark, those custom records will be emitted at that point. So I'm wondering if I could do anything via creating/resuming bookmarks to force the progress tracking records to be emitted at the appropriate time?

     

    • Marked as answer by drakc Thursday, April 7, 2011 11:06 AM
    Tuesday, March 22, 2011 12:00 PM
  • Hi, drakc

    ->"So I'm wondering if I could do anything via creating/resuming bookmarks to force the progress tracking records to be emitted at the appropriate time?"

    Yes, you can create every custom activity as bookmark activities. and please note that bookmark activity need be resumed by someone/something from the external world.

    If you create your activities all as bookmark activities and place them in a flowchart, you are actually creating a state machine like workflow - a event driven workflow.

    Regards 


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Wednesday, March 23, 2011 1:57 AM