December 2019
Intermediate to advanced
528 pages
11h 19m
English
When we install the service, we'll need to tell it where to look for the config file. We can do that by simply passing the parameter into the service. There are actually two ways to do this; the first (and the one that we're interested in) is to pass the parameter in during the installation of the service. This gets passed into the Main method. The second is passed in via the service management utility; the arguments are passed into the OnStart method of the service.
In our case, we're interested in changing the Main method:
static void Main(string[] args){ using (var service = new PhotoService(args[0]); ServiceBase.Run(service);}
Clearly, we'll need to accept that parameter in the constructor of PhotoService:
private readonly ...