Skip to content

Instantly share code, notes, and snippets.

@k4m4r82
Created August 22, 2017 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4m4r82/1713b5f3b53013a0cf2e0e5c199875cf to your computer and use it in GitHub Desktop.
Save k4m4r82/1713b5f3b53013a0cf2e0e5c199875cf to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using log4net;
namespace WindowsServiceGammu.Service
{
public partial class MainService : ServiceBase
{
private readonly List<TaskBase> _listOfTask;
private readonly ILog _log;
private const int RefreshInterval = 1000; // In milliseconds
public MainService()
{
InitializeComponent();
_log = Program.log;
// Add in this list the tasks to run periodically.
// Tasks frequencies are set in the corresponding classes.
_listOfTask = new List<TaskBase>
{
new SMSGatewayTask(RefreshInterval, _log)
};
}
protected override void OnStart(string[] args)
{
try
{
_log.Info("Services started ...");
_listOfTask.ForEach(t => t.StartService());
}
catch (Exception ex)
{
_log.Error("Error:", ex);
Stop();
}
}
protected override void OnStop()
{
_log.Info("Services stoped ...");
_listOfTask.ForEach(t => t.StopService());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment