L
labjac
Guest
Hallo
Hope somebody can assist, think I'm doing something wrong, followed the guidance on how to deploy a console application as a service to using TopShelf, but sure I'm doing something wrong, when running the console application with the exe it runs fine and without error, but when installing as a service it just shows Starting, but it's actually running and I got no control to Start,Stop,Pause or Reset. The actual program is another class, so the service is only controller a sequencer. (Which in returns call all the other part of the program.
Prgram section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace Adidas_Service
{
class Program
{
static void Main(string[] args)
{
var exitCode = HostFactory.Run(x =>
{
x.Service<Sequencer>(s =>
{
s.ConstructUsing(sequencer => new Sequencer());
s.WhenStarted(sequencer => sequencer.Start());
s.WhenStopped(sequencer => sequencer.Stop());
});
x.RunAsLocalSystem();
x.SetServiceName("AdidasWCS");
x.SetDisplayName("Adidas WCS Service");
x.SetDescription("This is managing the PTL Wall between PLC and Databases");
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
Environment.ExitCode = exitCodeValue;
}
}
}
Sequencer section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WCS_Shared.MainHandlerClasses.Logic;
using WCS_Shared.MainHandlerClasses.Symbols;
using WCS_Shared.SubHandlerClasses.Logic;
using WCS_Shared;
using System.Threading.Tasks;
using System.ServiceProcess;
namespace Adidas_Service
{
public class Sequencer
{
public Sequencer()
{
}
public void Start()
{
var newHuNrTriggerCycle = new NewHuNrTriggeredHandler();
var newHuTriggerHandlerSymbols = new NewHuNrTriggeredHandlersSymbols();
var monitorSequencerParameters = new MainSequencerParameterHandlerSymbols();
var getParameterSettings = new MainSequencerParametersHandler();
var sequencerEnabled = 1;
int sequenceCycleTimer = 0;
int counter = 1;
while (true)
{
monitorSequencerParameters = getParameterSettings.GetSequencerSettingParameters();
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
Thread.Sleep(2000);
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
while (sequencerEnabled > 0)
{
monitorSequencerParameters = getParameterSettings.GetSequencerSettingParameters();
sequenceCycleTimer = monitorSequencerParameters.applicationCycleSpeed;
SequencerRunner();
Thread.Sleep(sequenceCycleTimer);
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
}
Console.WriteLine("Sequencer Disabled");
}
}
public void Stop()
{
}
private void SequencerRunner()
{
var sequencer = new MainSequencerHandler();
var sequencerSymbols = new MainSequencerHandlerSymbols();
int cyclecounter = 1;
while (cyclecounter != 0)
{
sequencerSymbols = sequencer.MainSequencerHandlerSequencer();
cyclecounter = sequencerSymbols.sequencer;
}
}
}
}
labjac
Continue reading...
Hope somebody can assist, think I'm doing something wrong, followed the guidance on how to deploy a console application as a service to using TopShelf, but sure I'm doing something wrong, when running the console application with the exe it runs fine and without error, but when installing as a service it just shows Starting, but it's actually running and I got no control to Start,Stop,Pause or Reset. The actual program is another class, so the service is only controller a sequencer. (Which in returns call all the other part of the program.
Prgram section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace Adidas_Service
{
class Program
{
static void Main(string[] args)
{
var exitCode = HostFactory.Run(x =>
{
x.Service<Sequencer>(s =>
{
s.ConstructUsing(sequencer => new Sequencer());
s.WhenStarted(sequencer => sequencer.Start());
s.WhenStopped(sequencer => sequencer.Stop());
});
x.RunAsLocalSystem();
x.SetServiceName("AdidasWCS");
x.SetDisplayName("Adidas WCS Service");
x.SetDescription("This is managing the PTL Wall between PLC and Databases");
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
Environment.ExitCode = exitCodeValue;
}
}
}
Sequencer section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WCS_Shared.MainHandlerClasses.Logic;
using WCS_Shared.MainHandlerClasses.Symbols;
using WCS_Shared.SubHandlerClasses.Logic;
using WCS_Shared;
using System.Threading.Tasks;
using System.ServiceProcess;
namespace Adidas_Service
{
public class Sequencer
{
public Sequencer()
{
}
public void Start()
{
var newHuNrTriggerCycle = new NewHuNrTriggeredHandler();
var newHuTriggerHandlerSymbols = new NewHuNrTriggeredHandlersSymbols();
var monitorSequencerParameters = new MainSequencerParameterHandlerSymbols();
var getParameterSettings = new MainSequencerParametersHandler();
var sequencerEnabled = 1;
int sequenceCycleTimer = 0;
int counter = 1;
while (true)
{
monitorSequencerParameters = getParameterSettings.GetSequencerSettingParameters();
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
Thread.Sleep(2000);
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
while (sequencerEnabled > 0)
{
monitorSequencerParameters = getParameterSettings.GetSequencerSettingParameters();
sequenceCycleTimer = monitorSequencerParameters.applicationCycleSpeed;
SequencerRunner();
Thread.Sleep(sequenceCycleTimer);
sequencerEnabled = monitorSequencerParameters.sequencerEnabled;
}
Console.WriteLine("Sequencer Disabled");
}
}
public void Stop()
{
}
private void SequencerRunner()
{
var sequencer = new MainSequencerHandler();
var sequencerSymbols = new MainSequencerHandlerSymbols();
int cyclecounter = 1;
while (cyclecounter != 0)
{
sequencerSymbols = sequencer.MainSequencerHandlerSequencer();
cyclecounter = sequencerSymbols.sequencer;
}
}
}
}
labjac
Continue reading...