In my Windows Service project, the project looks to be started but actually not. A piece of related code is below:
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
g.Write2Log(g.logFolder, " WinService - PhotoFile: ServicesToRun before start " + DateTime.Now);
try {
ServiceBase.Run(ServicesToRun);
g.Write2Log(g.logFolder, " WinService - PhotoFile: ServicesToRun after start " + DateTime.Now);
} catch (Exception ex) {
g.Write2Log(g.logFolder, "ServicesToRun can't be launched - Exception: " + ex.Message + " " + DateTime.Now);
}
In my log file, the "ServicesToRun before start" message displays but the
"ServicesToRun after start" never displays. It means the
ServicesToRun = new ServiceBase[] { new Service1() }
is actually not called, on OnStart() event is not fired.
Referring to
c# - Allow service to interact with desktop in Windows - Stack Overflow[
^]
I checked on "Allow service to interact with desktop", but the problem still exists. What else should do for this bug? Thanks.
What I have tried:
Window Service actually not started properly