How to determine if Topshelf is in console mode

I use Topshelf in conjunction with FluentSchedule for a Windows service.

However, I want to be able to test run the application, just to run and not run the FluentSchedule code that sets the timer, etc.

Is there a way to run an exe file from the command line (that is, without the "install" command) to check from TopShelf that it is running in console mode?

+8
topshelf
source share
2 answers

This is a kind of hack, but you can try to apply the HostControl interface to ConsoleRunHost , and if it is this type, you start the console application.

This is not ideal, of course, but you can hide it in the extension method to make it less ugly.

 public static bool IsRunningAsConsole(this HostControl control) { return control is ConsoleRunHost; } 
+12
source share

You can use Environment.UserInteractive . Technically, this will not work in 100% of cases, since you can start the service online, but this is a random case.

+7
source share

All Articles