Created
August 22, 2017 07:52
-
-
Save k4m4r82/1713b5f3b53013a0cf2e0e5c199875cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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