Browse Source

Address another Milliseconds misusage (similar to #124)

Oleg Nenashev 9 years ago
parent
commit
2a07f6af5d
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/Core/ServiceWrapper/Main.cs

+ 14 - 1
src/Core/ServiceWrapper/Main.cs

@@ -473,9 +473,22 @@ namespace winsw
 
         private void SignalShutdownPending()
         {
+            int effectiveWaitHint;
+            if (_descriptor.WaitHint.TotalMilliseconds > Int32.MaxValue)
+            {
+                Log.Warn("The requested WaitHint value (" + _descriptor.WaitHint.TotalMilliseconds + " ms)  is greater that the max value " + 
+                    Int32.MaxValue + ". The value will be truncated");
+                effectiveWaitHint = Int32.MaxValue;
+            }
+            else
+            {
+                effectiveWaitHint = (int)_descriptor.WaitHint.TotalMilliseconds;
+            }
+
+
             IntPtr handle = ServiceHandle;
             _wrapperServiceStatus.checkPoint++;
-            _wrapperServiceStatus.waitHint = _descriptor.WaitHint.Milliseconds;
+            _wrapperServiceStatus.waitHint = effectiveWaitHint;
 //            WriteEvent("SignalShutdownPending " + wrapperServiceStatus.checkPoint + ":" + wrapperServiceStatus.waitHint);
             _wrapperServiceStatus.currentState = (int)State.SERVICE_STOP_PENDING;
             Advapi32.SetServiceStatus(handle, ref _wrapperServiceStatus);