Table of Contents [Hide/Show]
Overview Walkthrough Creating the Project and Objects Coding the Service Deploying and Testing the Service
class Program { static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WeatherWidgetService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Text; using System.IO; namespace Weather_Widget_Service { partial class WeatherWidgetService : ServiceBase { public WeatherWidgetService() { InitializeComponent(); } protected override void OnStart(string[] args) { // TODO: Add code here to start your service. WriteLog("Service started"); } protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop // your service. WriteLog("Service stopped"); } private void WriteLog(string msg) { msg = "\n" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + ">" + msg; File.AppendAllText(@"C:\Data\WeatherService.log", msg); } } }
bin\Debug
bin\Release
installutil /u WeatherWidgetService.exe
installutil WeatherWidgetService.exe
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.