Creating a Windows Service with C#, continued
(Page 1 of 4 )
This article, the second in a three-part series, covers what you need to do to convert a console application into a Windows Service and install it.
The Zip file containing the source code for this and the other parts of this series can be found HERE.
In the first part of this series we created a rudimentary TCP server that gives out the current date and time. In this article we will convert that console application into a Windows Service and install it. The transition will be mostly painless but there are a few considerations.
First, we cannot rely on a keypress to stop our server anymore. We will have to implement the OnStop() method for the service, which is called implicitly when Windows attempts to stop a service. Second, we need some way to know that the server is working without having to run the test client all the time, so we will add code to the server to log to a custom Windows Event Log.
We will address all these things in this article. In the third and final article, we will create a Windows Form application to run in the system tray that will allow us to stop and start the server. We will also add pause and continue functionality, which is a lot simpler than it sounds! For now, though, we will concern ourselves with getting the service built and installed.
Next: Creating the Windows Service Project >>
More C# Articles
More By David Fells