コード例 #1
0
 protected void ConfigureFailureActions()
 {
     base.DoNativeServiceTask(this.Name, ServiceAccessFlags.AllAccess, delegate(IntPtr service)
     {
         IntPtr intPtr = IntPtr.Zero;
         TaskLogger.Trace("Configuring failure actions...", new object[0]);
         try
         {
             ServiceFailureActions serviceFailureActions = default(ServiceFailureActions);
             serviceFailureActions.resetPeriod           = this.FailureResetPeriod;
             serviceFailureActions.rebootMessage         = null;
             serviceFailureActions.command     = null;
             serviceFailureActions.actionCount = 3U;
             int num = Marshal.SizeOf(typeof(ServiceAction));
             intPtr  = Marshal.AllocHGlobal((int)((long)num * (long)((ulong)serviceFailureActions.actionCount)));
             serviceFailureActions.actions = intPtr;
             this.ConfigureFailureAction(intPtr, num, 0, this.firstFailureActionType, this.firstFailureActionDelay);
             this.ConfigureFailureAction(intPtr, num, 1, this.secondFailureActionType, this.secondFailureActionDelay);
             this.ConfigureFailureAction(intPtr, num, 2, this.allOtherFailuresActionType, this.allOtherFailuresActionDelay);
             if (!NativeMethods.ChangeServiceConfig2(service, ServiceConfigInfoLevels.FailureActions, ref serviceFailureActions))
             {
                 base.WriteError(TaskWin32Exception.FromErrorCodeAndVerbose(Marshal.GetLastWin32Error(), Strings.ErrorChangeServiceConfig2(this.Name)), ErrorCategory.WriteError, null);
             }
         }
         finally
         {
             if (IntPtr.Zero != intPtr)
             {
                 Marshal.FreeHGlobal(intPtr);
             }
         }
     });
 }
コード例 #2
0
 public static extern bool ChangeServiceConfig2(IntPtr serviceController, ServiceConfigInfoLevels infoLevel, ref ServiceFailureActions failureActions);