Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4108134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:36:42+00:00 2026-05-20T21:36:42+00:00

I have a long running activity (where the activity is continually doing work for

  • 0

I have a long running activity (where the activity is continually doing work for a long period of time – not an activity that is waiting for a response from an external source) and I want to report progress from that activity. However, I cannot get this to work.

I have a simple console app that runs the activity:

class Program
{
    static void Main(string[] args)
    {
        var wfApp = new WorkflowApplication(new ActivityLibrary.ProgressActivity());

        var autoResetEvent = new AutoResetEvent(false);
        wfApp.Completed = e => autoResetEvent.Set();
        wfApp.Extensions.Add(new ConsoleTrackingParticipant());
        wfApp.Run();
        autoResetEvent.WaitOne();

        Console.WriteLine("Done");
        Console.ReadLine();
    }
}

internal class ConsoleTrackingParticipant : TrackingParticipant
{
    protected override void Track(TrackingRecord record, TimeSpan timeout)
    {
        Console.WriteLine(record.EventTime.ToString());
    }
}

I’ve tried implementing the ProgressActivity in two ways. First I tried deriving from CodeActivity, but when I use this implementation I receive all the custom tracking records together once the workflow has completed (though the reported record.EventTime is correct):

public sealed class ProgressActivity : CodeActivity
{
    protected override void Execute(CodeActivityContext context)
    {
        for (var i = 0; i <= 10; i++)
        {
            var customTrackingRecord = new CustomTrackingRecord("ProgressTrackingRecord")
                {
                    Data = { { "Progress", i * 10.0 }}
                };

            context.Track(customTrackingRecord);
            Thread.Sleep(1000);
        }
    }
}

I then tried deriving from AsyncCodeActivity, but in this case I get an “ObjectDisposedException: An ActivityContext can only be accessed within the scope of the function it was passed into” on the context.Track line:

public sealed class ProgressActivity : AsyncCodeActivity
{
    protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
    {
        Action action = () =>
            {
                for (var i = 0; i <= 10; i++)
                {
                    var customTrackingRecord = new CustomTrackingRecord("ProgressTrackingRecord")
                    {
                        Data = { { "Progress", i * 10.0 } }
                    };

                    context.Track(customTrackingRecord);
                    Thread.Sleep(1000);
                }
            };

        context.UserState = action;
        return action.BeginInvoke(callback, state);
    }

    protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
    {
        ((Action)context.UserState).EndInvoke(result);
    }
}

Can anyone explain where I’ve gone wrong?

P.S. I realise that the approach I’ve shown would not scale well if the workflow was ever to run on a server, but the application I’m building is a desktop application.

[EDIT]
I guess I’m actually asking a broader question here: when are tracking records emitted by the workflow execution engine? My investigations suggest that all the records for a specific activity are emitted after the activity has completed. Is there any way to force them to be emitted during the execution of the activity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:36:43+00:00Added an answer on May 20, 2026 at 9:36 pm

    I’ve also asked this question on the MSDN workflow forum, and done some further investigation myself based on the comments I received there. As a result I think that tracking records are emitted when the activity completes or is bookmarked. See http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/8ce5dee9-9a19-4445-ad7f-33e181ec228b for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET site that has been running perfectly for a long time,
I have a lot of long-running activities and think that spawning this activity off
I have a long running SQL statement that I want to run, and no
I have a long running process in VB6 that I want to finish before
I have several long running report type transactions that take 5-10 minutes. Would I
I have a long running insert transaction that inserts data into several related tables.
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I have a web application that needs to fire off a long-running SQL Server
I have a backroundrb scheduled task that takes quite a long time to run.
We have a long running data transfer process that is just an asp.net page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.