Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public sealed class GeradorDeRelatorio : ServiceControl
{
private readonly CancellationTokenSource _cancellationTokenSource;
public GeradorDeRelatorio()
{
_cancellationTokenSource = new CancellationTokenSource();
}
public bool Start(HostControl hostControl)
{
Task.Run(() =>
{
while (true)
{
//Gera relatorio
Thread.Sleep(TimeSpan.FromSeconds(5));
}
}, _cancellationTokenSource.Token);
return true;
}
public bool Stop(HostControl hostControl)
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource.Dispose();
return true;
}
}
Install-Package Topshelf
public class Program
{
public static void Main(string[] args)
{
HostFactory.Run(configurator =>
{
configurator.Service<GeradorDeRelatorio>(s =>
{
s.ConstructUsing(name => new GeradorDeRelatorio());
s.WhenStarted((service, control) => service.Start(control));
s.WhenStopped((service, control) => service.Stop(control));
});
configurator.RunAsLocalSystem();
configurator.SetDescription("Sample Topshelf Host");
configurator.SetDisplayName("Stuff");
configurator.SetServiceName("Stuff");
});
}
}
public class Program
{
public static void Main(string[] args)
{
HostFactory.Run(configurator =>
{
configurator.UseNinject(new MeuNinjectModule(), new MeuNinjectModule2());
configurator.Service<GeradorDeRelatorio>(s =>
{
s.ConstructUsingNinject();
s.WhenStarted((service, control) => service.Start(control));
s.WhenStopped((service, control) => service.Stop(control));
});
configurator.RunAsLocalSystem();
configurator.SetDescription("Sample Topshelf Host");
configurator.SetDisplayName("Stuff");
configurator.SetServiceName("Stuff");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment