Windows Workflow Foundation (WF4) - Workflow Services and Auto-Start

This sample application demonstrates how you can create a Workflow Service that will automatically start and periodically wake up to do some work. The sample also demonstrates a UI that shows the progress of the work and provides control and query capabilities.

C# (249.0 KB)
 
 
 
 
 
4 Star
(6)
4,298 times
Add to favorites
4/28/2011
E-mail Twitter del.icio.us Digg Facebook
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TraceBatchWork.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <summary>
//   The trace batch work.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace BatchWeb
{
    using System;
    using System.Activities;
    using System.Activities.Tracking;
    using System.Diagnostics;

    using BatchWorker.Contracts;

    /// <summary>
    /// The trace batch work.
    /// </summary>
    public sealed class TraceBatchWork : CodeActivity
    {
        // Define an activity input argument of type string
        #region Properties

        /// <summary>
        /// Gets or sets Response.
        /// </summary>
        public InArgument<BatchInfoResponse> Response { get; set; }

        #endregion

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        #region Methods

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        protected override void Execute(CodeActivityContext context)
        {
            var response = this.Response.Get(context);

            var message = string.Format(
                "Job: {0} Count {1}/{2}, LastUpdate {3}", 
                response.JobId, 
                response.CurrentCount, 
                response.CountingTo, 
                response.LastUpdate == DateTime.MinValue ? "None" : response.LastUpdate.ToString());
            Trace.WriteLine(message);
            context.Track(new CustomTrackingRecord(message));
        }

        #endregion
    }
}