/// <summary>
/// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.
/// </summary>
/// <param name="args">Data passed by the start command.</param>
protected override void OnStart(string[] args)
{
if (_tvServiceThread == null)
{
if (!(args != null && args.Length > 0 && args[0] == "/DEBUG"))
{
RequestAdditionalTime(60000); // starting database can be slow so increase default timeout
}
TvServiceThread tvServiceThread = new TvServiceThread();
ThreadStart tvServiceThreadStart = new ThreadStart(tvServiceThread.OnStart);
_tvServiceThread = new Thread(tvServiceThreadStart);
_tvServiceThread.IsBackground = false;
// apply process priority on initial service start.
if (!_priorityApplied)
{
try
{
applyProcessPriority();
_priorityApplied = true;
}
catch (Exception ex)
{
// applyProcessPriority can generate an exception when we cannot connect to the database
Log.Error("OnStart: exception applying process priority: {0}", ex.StackTrace);
}
}
var layer = new TvBusinessLayer();
layer.SetLogLevel();
_tvServiceThread.Start();
while (!TvServiceThread.Started)
{
Thread.Sleep(20);
}
}
}