Question

I was checking the TopShelf as a beginner.

I see that when you compile your console app you can install your service as:

MySampleWindowsService.exe install

and start:

MySampleWindowsService.exe start

What I do not understand is my console app does not do anything with those parameters.

Question:So how the TopShelf captures those 'install' or 'start' arguments?

Was it helpful?

Solution

It probably uses Environment.CommandLine or Environment.GetCommandLineArgs.

The command line of a process is stored in a special area of memory set aside when the process is created, which is how it's available at any time during the process's execution. It can be retrieved by the native GetCommandLine function, which is the "official" way of getting command-line arguments in a Windows process, and is wrapped by the .NET Environment members.

Passing the command line as parameters to the "main" function in many languages is a convenience provided by the language. The compiler generates startup code that calls GetCommandLine and passes the result as a parameter to main (or equivalent). Similarly, the return value (if any) from main is usually set as the process's exit code by compiler-generated process tear-down logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top