Reputation: 61
My program can run as console program or Windows service. However, when program runs as a service, it runs Main(string[] args)
too.
And my Main()
method have some code that can not use in windows service.
How can I determine if my program is running as a service?
Upvotes: 0
Views: 325
Reputation: 100527
One approach is to use command line argument to specify that (and obviously check in Main
). I.e. when configuring service set command line argument to "-asservice" and than in Main
check if this argument is passed in. I.e.
if(args.Any(a => a == "-asservice"))
{
// running as service...
}
Upvotes: 1