I have a program that is written to run in the foreground. But it backgrounds itself on some machines.
Here is the context.
I h开发者_如何学Pythonave a class derived from ServiceBase,
public class MyService: ServiceBase
For debug purposes, I do not start the service as follows:
ServiceBase.Run(myService);
Instead, I invoke the OnStart directly as follows, and sleep forever:
myService.OnStart(null);
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
For some reason the process is backgrounding itself on the production machine. Ideas?
Turns out this was because VS sets OutputType of a service project to WinExe (as opposed to Exe for a console application). WinExe executables background themselves. And the behavior seemed to be different on two machines, because on one I was in the cygwin shell, where, for some reason, it does not background itself.
I believe that Windows actually does or can pay-attention to the status of the 'main' thread running your application. If it sees that the 'main' thread is sleeping, then IIRC it can background the whole process. The choice of when or what to background often is related to energy-saving features, such as on a laptop.
精彩评论