From 3b3591d66fbd8dacf0c93a724cdb7ebea6e7ed81 Mon Sep 17 00:00:00 2001 From: jjasper4 Date: Sun, 8 Feb 2009 19:50:19 +0000 Subject: [PATCH] make settings configurable git-svn-id: https://svn.kenai.com/svn/winsw~subversion/trunk@29 c8b2a3fe-9b5b-6a51-a37e-dc31b0e308fa --- Main.cs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/Main.cs b/Main.cs index 1989646..a424751 100644 --- a/Main.cs +++ b/Main.cs @@ -285,6 +285,63 @@ namespace winsw } } + /// + /// True if the service should when finished on shutdown. + /// + public bool BeepOnShutdown + { + get + { + return dom.SelectSingleNode("//beeponshutdown") != null; + } + } + + + /// + /// The estimated time required for a pending stop operation, in milliseconds (default 15 secs). + /// Before the specified amount of time has elapsed, the service should make its next call to the SetServiceStatus function + /// with either an incremented checkPoint value or a change in currentState. (see http://msdn.microsoft.com/en-us/library/ms685996.aspx) + /// + public int WaitHint + { + get + { + XmlNode waithintNode = dom.SelectSingleNode("//waithint"); + + if (waithintNode == null) + { + return 15000; + } + else + { + return int.Parse(waithintNode.InnerText); + } + } + } + + + /// + /// The time, in milliseconds (default 1 sec), before the service should make its next call to the SetServiceStatus function + /// with an incremented checkPoint value. + /// Do not wait longer than the wait hint. A good interval is one-tenth of the wait hint but not less than 1 second and not more than 10 seconds. + /// + public int SleepTime + { + get + { + XmlNode sleeptimeNode = dom.SelectSingleNode("//sleeptime"); + + if (sleeptimeNode == null) + { + return 1000; + } + else + { + return int.Parse(sleeptimeNode.InnerText); + } + } + } + /// /// True if the service can interact with the desktop. /// @@ -564,6 +621,8 @@ namespace winsw } else { + SignalShutdownPending(); + stoparguments += " " + descriptor.Arguments; Process stopProcess = new Process(); @@ -580,6 +639,10 @@ namespace winsw WaitForProcessToExit(process); WaitForProcessToExit(stopProcess); SignalShutdownComplete(); + } + + if (systemShuttingdown && descriptor.BeepOnShutdown) + { Console.Beep(); } @@ -594,7 +657,7 @@ namespace winsw { // WriteEvent("WaitForProcessToExit [start]"); - while (!process.WaitForExit(1000)) + while (!process.WaitForExit(descriptor.SleepTime)) { SignalShutdownPending(); // WriteEvent("WaitForProcessToExit [repeat]"); @@ -612,7 +675,7 @@ namespace winsw { IntPtr handle = this.ServiceHandle; wrapperServiceStatus.checkPoint++; - wrapperServiceStatus.waitHint = 10000; + wrapperServiceStatus.waitHint = descriptor.WaitHint; // WriteEvent("SignalShutdownPending " + wrapperServiceStatus.checkPoint + ":" + wrapperServiceStatus.waitHint); wrapperServiceStatus.currentState = (int)State.SERVICE_STOP_PENDING; SetServiceStatus(handle, ref wrapperServiceStatus);