Click here to Skip to main content
15,894,646 members
Articles / Programming Languages / C#

Creating a C# Service Step-by-Step Lesson II

Rate me:
Please Sign up or sign in to vote.
4.85/5 (31 votes)
9 Apr 20033 min read 195.9K   1.6K   179  
A multi-article contribution describing in step-by-step detail on creating your own service with integrated support for setup and custom event logs. This lesson we'll add multiple child services as well as updating the installer to install these services as well.
using System;
using System.ServiceProcess;

namespace CodeBlooded.Spades.Services
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Application
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			// we'll go ahead and create an array so that we can add the different services that
			// we'll create over time.
			ServiceBase[]	servicesToRun;

			// to create a new instance of a new service, just add it to the list of services 
			// specified in the ServiceBase array constructor.
			servicesToRun = new ServiceBase[] { new SpadesAdminService(), 
												new SpadesLoginService(),
												new SpadesGameService(),
												new SpadesLobbyService()
											  };

			// now run all the service that we have created. This doesn't actually cause the services
			// to run but it registers the services with the Service Control Manager so that it can
			// when you start the service the SCM will call the OnStart method of the service.
			ServiceBase.Run( servicesToRun );
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Match.com
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