❔ ServiceBase question: is Main() or OnStart() my entry point?
I have a program that extends
ServiceBase
. I am given a method to override called OnStart()
. When my app is running as a windows service, is this the entry point? The tutorial I followed also has me calling ServiceBase.Run()
in my Main()
method.
The reason I'm asking is because I'm trying to decide where I should set up my logger. My app also needs to run as a console app. My Main()
method has a Environment.UserInteractive
branch. If user interactive, I run as a console app. If not user interactive, I call ServiceBase.Run()
. If this is the incorrect approach, feedback would be much appreciated!3 Replies
Upon reading the docs https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.run?view=netframework-4.8 it looks like
Main()
is still my entry point.OnStart seems like empty virtual method to add some actions on startup, I would assume it is called inside
Run()
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.