Click here to Skip to main content
15,892,674 members
Articles / Desktop Programming / Windows Forms

Windows Services Made Simple

Rate me:
Please Sign up or sign in to vote.
4.62/5 (10 votes)
27 Jun 2007CPOL10 min read 94.5K   6.9K   69  
Describes how to build a Windows Service using the Pegasus Library.
using System;

using Pegasus.Workflow.Service;

namespace Pegasus.UnitTests.Workflow.Service.Workflows
{
	/// <summary>
	/// Testing data exchange service
	/// </summary>
	public class TestDataExchangeService : WorkflowDataExchangeService
	{
		// Local Instance Values
		private bool m_startCalled = false;
		private bool m_stopCalled = false;

		/// <summary>
		/// Gets a value indicating whether start method was called.
		/// </summary>
		/// <value><c>true</c> if called; otherwise, <c>false</c>.</value>
		public bool StartCalled
		{
			get
			{
				return m_startCalled;
			}
		}

		/// <summary>
		/// Gets a value indicating whether the stop method was called.
		/// </summary>
		/// <value><c>true</c> if called; otherwise, <c>false</c>.</value>
		public bool StopCalled
		{
			get
			{
				return m_stopCalled;
			}
		}

		/// <summary>
		/// Starts this instance of the service.
		/// </summary>
		/// <param name="workflowService"></param>
		public override void Start( WorkflowService workflowService )
		{
			base.Start( workflowService );
			m_startCalled = true;
		}

		/// <summary>
		/// Stops this instance of the service.
		/// </summary>
		public override void Stop()
		{
			base.Stop();
			m_stopCalled = true;
		}

		/// <summary>
		/// Fires the first event.
		/// </summary>
		/// <param name="args">The <see cref="T:Pegasus.UnitTests.Workflow.Service2.Workflows.TestingEventArgs"/> instance containing the event data.</param>
		public void FireFirstEvent( TestingEventArgs args )
		{
			if( FirstEvent != null )
			{
				FirstEvent( this, args );
			}
		}

		/// <summary>
		/// Fires the second event.
		/// </summary>
		/// <param name="args">The <see cref="T:Pegasus.UnitTests.Workflow.Service2.Workflows.TestingEventArgs"/> instance containing the event data.</param>
		public void FireSecondEvent( TestingEventArgs args )
		{
			if( SecondEvent != null )
			{
				SecondEvent( this, args );
			}
		}

		/// <summary>
		/// Fires the third event.
		/// </summary>
		/// <param name="args">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		public void FireThirdEvent( EventArgs args )
		{
			if( ThirdEvent != null )
			{
				ThirdEvent( this, args );
			}
		}

		/// <summary>
		/// Custom delegate handler to make sure we can tie up customer delegates.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="args"></param>
		public delegate void CustomerDelegateHandler( object sender, TestingEventArgs args );

		/// <summary>
		/// Event using a generic event handler
		/// </summary>
		public event EventHandler<TestingEventArgs> FirstEvent;

		/// <summary>
		/// Event using a custom event handler
		/// </summary>
		public event CustomerDelegateHandler SecondEvent;

		/// <summary>
		/// Event that uses standard event handler (for unable to bind test)
		/// </summary>
		public event EventHandler ThirdEvent;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions