標籤:des blog http os io for art cti
最近看了看windows service,
1. 找到了一個文章:http://blog.csdn.net/knight94/article/details/627298
2. At the end of the link http://www.cnblogs.com/Googler/archive/2013/07/23/3208354.html , there is a sentance: The "Interact with Desktop" option is not supported by Microsoft in Windows Vista and newer. So use it wisely and redesign your app if there is a solid chance that your service can be installed on Vista or Server 2008.
應該是因為這個原因:我在Win7中安裝了一個windows service, 這個windows service的主要功能是啟動一個windows Form app. 當啟動這個service的時候,總是會報這個錯誤:
This problem occurs when a program is not fully compatible with Windows. Please contact the program or device manufacturer(s) for more information. in the Interactive Services Detection dialog.
3. windows service Properties:
Log On ---> Allow service to interact with desktop.
4. Debug windows service:
there is a way to debug the windows service:
1). Modify "Output type" to "Windows Application" in the serivce project property tab page.
2). in the Main(), to add the following code in Program.cs:
static void Main()
{
if (Environment.UserInteractive)
{
string[] args = {"", ""};
Service service = new Service();
service.Start(args);
}
else
{
ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
//another service to this process, change the following line to
// create a second service object. For example,
//
ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new ServiceBase[] { new Service() };
ServiceBase.Run(ServicesToRun);
}
}