accessing 'start parameters', debugging topshelf and programmatically stopping

528 views
Skip to first unread message

Neil Walker

unread,
Oct 31, 2014, 6:38:54 PM10/31/14
to topshelf...@googlegroups.com
Hello,
I've spent some time setting things up that seem to work very nicely, but it was painful without being able to debug. Anyway, can anyone help with the following as after a few days playing this is my only outstanding issues:

1. I added command line support as follows:

             HostFactory.Run(hostConfigurator =>
            {
                hostConfigurator.AddCommandLineDefinition("params", f => { startParams = f; });
                hostConfigurator.ApplyCommandLine(); 

Which is fine from the commandline, but I wish to access something similar from the running service. I assumed the 'start parameters' option in the service dialog would equate to the same thing, but it's not. Can somebody tell me how to access 'start parameters' please?


2. I wish to programmatically stop the service, but I can't see how. Is there a way? I can throw and exception but that doesn't look nice and it's always 'error 5: access denied'?

3. How do I debug the program running as a service? my program initially crashed in startup or just after it started so attaching the debugger doesn't help, I want to be able to run the program from within Visual Studio as a service. Or if not, maybe just how to attach the debugger before it starts processing would help.

Thanks for your help.

Neil.

Chris Patterson

unread,
Nov 2, 2014, 12:16:36 AM11/2/14
to topshelf...@googlegroups.com
If it runs properly from visual studio or the command-line, but crashes as a service, it's ALMOST ALWAYS security permissions related. There should be other articles about how to debug a service startup, debugging Topshelf running as a service should be the same.


--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neil Walker

unread,
Nov 2, 2014, 9:51:04 AM11/2/14
to topshelf...@googlegroups.com
Ok. So how do I stop it programmatically? no matter what I do it just sits there (in console) with the message 'press ctrl-c' and I cannot find any way to kill it other than an unhandled exception.

Neil.

Chris Patterson

unread,
Nov 2, 2014, 11:18:56 AM11/2/14
to topshelf...@googlegroups.com
You can press Control+C, or you can call HostControl.Stop() (the hostControl instance is passed to both the start and stop methods on the service itself).

Reply all
Reply to author
Forward
0 new messages