topshelf

Installing a Topshelf application as a Windows service

心不动则不痛 提交于 2019-12-03 04:42:51
问题 Using Visual Studio Express 2012, I've created a console application using Topshelf (Version 3.1.107.0). The application works as a console application, but I can't figure out how to install it as a service. I've published the project from within Visual Studio (Build, Publish), started a command prompt as Administrator, navigated to the folder where the application was published, and run setup.exe -install from the command prompt. The application is installed and runs, but as a console

How to handle async Start() errors in TopShelf

孤街醉人 提交于 2019-12-03 04:02:38
I have a TopShelf service that uses async code to connect to web services and other application servers. If it's unable to initialize its connections on startup, the service should log some errors and gracefully stop. I've had a look at this question about stopping TopShelf when the start conditions aren't met. This answer talks about using the TopShelf HostControl to stop the service. However, that answer relies on the ServiceConfigurator<T>.WhenStarted<T>(Func<T, HostControl, bool> start) method. I am currently configuring the TopShelf service in the standard way: x.Service<MyService>(s => {

Installing a Topshelf application as a Windows service

半城伤御伤魂 提交于 2019-12-02 17:49:46
Using Visual Studio Express 2012, I've created a console application using Topshelf (Version 3.1.107.0). The application works as a console application, but I can't figure out how to install it as a service. I've published the project from within Visual Studio (Build, Publish), started a command prompt as Administrator, navigated to the folder where the application was published, and run setup.exe -install from the command prompt. The application is installed and runs, but as a console application, not a Windows service. What am I missing here? For those who may not be familiar with Topshelf,

How do I force a quartz.net job to restart intervall after completion

本秂侑毒 提交于 2019-12-02 01:12:48
I have a project where I use TopShelf and TopShelf.Quartz Following this example I am building my jobs with s.ScheduleQuartzJob(q => q.WithJob(() => JobBuilder.Create<MyJob>().Build()) .AddTrigger(() => TriggerBuilder.Create() .WithSimpleSchedule(builder => builder .WithIntervalInSeconds(5) .RepeatForever()) .Build()) ); which fires my job every five seconds even if the previous is still running. What I really want to achive is to start a job and after the completion wait five seconds and start again. Is this possible or do I have to implement my own logic (for example via a static variable).

How to specify command line options for service in TopShelf

主宰稳场 提交于 2019-12-01 03:44:09
I am using command line arguments to pass some configuration to the windows service (it will be few instances with different command lines). My code looks like this: HostFactory.Run(x => { x.Service<MyHost>(s => { s.ConstructUsing(name => new MyHost()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); x.AddCommandLineDefinition("sqlserver", v => sqlInstance = v); }); When I install service I use: myhost.exe install -sqlserver:someinstance Unfortunately, sqlserver command line options is available only on install phase, and do not go to the parameters of the service. So when

How to catch exception and stop Topshelf service?

牧云@^-^@ 提交于 2019-11-30 08:20:24
I have a topshelf windows service where I want to do some checking (i.e. if an xml file exists) and if the check fails I need the windows service to stop. So I tried doing the check in the Start() method and then raise an exception: public void Start() { if (!File.Exists(_xmlFile) throw new FileNotFoundException(); // Do some work here if xml file exists. } However, the windows service stays around as a process after the exception which I then have to kill manually in the task manager. Is there a way to not run the service if certain conditions (i.e. file not found) hold? I've "borrowed" the

Console.WriteLine() inside a Windows Service?

流过昼夜 提交于 2019-11-29 02:51:11
I am currently using TopShelf with a Console Application to create a Windows Service. When I run the code as a console application I use a few Console.WriteLine() to output results. Once the code does what it is supposed to do I install the console application as a Windows Service. Are there any downsides with leaving the Console.WriteLine() code even though a Windows Service can not write to the console? Are there any risks of having unstable code if I leave the Console.WriteLine() in there? dtech The output will simply be discarded . In a Windows Service there is no Console so Console.Write*

Console.WriteLine() inside a Windows Service?

六眼飞鱼酱① 提交于 2019-11-27 03:03:08
问题 I am currently using TopShelf with a Console Application to create a Windows Service. When I run the code as a console application I use a few Console.WriteLine() to output results. Once the code does what it is supposed to do I install the console application as a Windows Service. Are there any downsides with leaving the Console.WriteLine() code even though a Windows Service can not write to the console? Are there any risks of having unstable code if I leave the Console.WriteLine() in there?