public void SetData()
        {
            cbFirstfailure.Items.AddRange(sFailureMsgs);
            cbSecondFailure.Items.AddRange(sFailureMsgs);
            cbSubsquentFailure.Items.AddRange(sFailureMsgs);

            cbFirstfailure.SelectedIndexChanged -= new EventHandler(this.cbFirstfailure_SelectedIndexChanged);
            cbSecondFailure.SelectedIndexChanged -= new EventHandler(this.cbFirstfailure_SelectedIndexChanged);
            cbSubsquentFailure.SelectedIndexChanged -= new EventHandler(this.cbFirstfailure_SelectedIndexChanged);

            cbFirstfailure.SelectedItem = cbSecondFailure.SelectedItem = cbSubsquentFailure.SelectedItem = sFailureMsgs[0];

            failureActions = ServiceManagerWindowsWrapper.ApiQueryServiceConfig2(serviceName);
            ServiceManagerApi.SC_ACTION[] actions = new ServiceManagerApi.SC_ACTION[failureActions.cActions];
            int offset = 0;
            for (int i = 0; i < failureActions.cActions; i++)
            {
                ServiceManagerApi.SC_ACTION action = new ServiceManagerApi.SC_ACTION();
                action.Type = Marshal.ReadInt32(failureActions.lpsaActions, offset);
                offset += sizeof(Int32);
                action.Delay = (Int32)Marshal.ReadInt32(failureActions.lpsaActions, offset);
                offset += sizeof(Int32);
                actions[i] = action;

                switch (action.Type)
                {
                    case (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_NONE:
                        txtDays.Text = action.Delay.ToString();
                        if (i == 0)
                            cbFirstfailure.SelectedItem = 0;
                        else if (i == 1)
                            cbSecondFailure.SelectedItem = 0;
                        else
                            cbSubsquentFailure.SelectedItem = 0;
                        break;

                    case (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_REBOOT:
                        txtMinutes.Text = action.Delay.ToString();
                        if (i == 0)
                            cbFirstfailure.SelectedItem = 3;
                        else if (i == 1)
                            cbSecondFailure.SelectedItem = 3;
                        else
                            cbSubsquentFailure.SelectedItem = 3;
                        break;

                    case (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_RESTART:
                        btnBrowse.Enabled = true;
                        if (i == 0)
                            cbFirstfailure.SelectedItem = 1;
                        else if (i == 1)
                            cbSecondFailure.SelectedItem = 1;
                        else
                            cbSubsquentFailure.SelectedItem = 1;
                        break;

                    case (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_RUN_COMMAND:
                        txtProgram.Text = failureActions.lpCommand;
                        if (i == 0)
                            cbFirstfailure.SelectedItem = 2;
                        else if (i == 1)
                            cbSecondFailure.SelectedItem = 2;
                        else
                            cbSubsquentFailure.SelectedItem = 2;
                        break;

                    default:
                        break;
                }
            }
            if (failureActions.cActions != 0)
                SetControlStates(sFailureMsgs[0]);

            cbFirstfailure.SelectedIndexChanged += new EventHandler(this.cbFirstfailure_SelectedIndexChanged);
            cbSecondFailure.SelectedIndexChanged += new EventHandler(this.cbFirstfailure_SelectedIndexChanged);
            cbSubsquentFailure.SelectedIndexChanged += new EventHandler(this.cbFirstfailure_SelectedIndexChanged);
        }
        public bool OnApply()
        {
            Logger.Log("In ServiceRecoveryPage: OnApply()");

            ServiceManagerApi.SERVICE_FAILURE_ACTIONS failureActionUpdate = new ServiceManagerApi.SERVICE_FAILURE_ACTIONS();
            failureActions.cActions = 2;
            IntPtr lpsaActions = IntPtr.Zero;

            ServiceManagerApi.SC_ACTION action = new ServiceManagerApi.SC_ACTION();
            if (txtDays.Enabled)
            {
                action.Type = (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_NONE;
                action.Delay = (int)TimeSpan.FromMinutes(int.Parse(txtDays.Text.Trim())).TotalMilliseconds;

                lpsaActions = Marshal.AllocHGlobal(Marshal.SizeOf(action) * 2);
                if (lpsaActions == IntPtr.Zero)
                {
                    Logger.Log(String.Format("Unable to allocate memory for service action, error was: 0x{0:X}", Marshal.GetLastWin32Error()));
                }
                Marshal.StructureToPtr(action, lpsaActions, false);
                if (txtMinutes.Enabled)
                {
                    action = new ServiceManagerApi.SC_ACTION();
                    action.Type = (int)ServiceManagerApi.SC_ACTION_TYPE.SC_ACTION_RESTART;
                    action.Delay = (int)TimeSpan.FromMinutes(int.Parse(txtMinutes.Text.Trim())).TotalMilliseconds;

                    IntPtr nextAction = (IntPtr)(lpsaActions.ToInt64() + Marshal.SizeOf(action));
                    Marshal.StructureToPtr(action, nextAction, false);
                }
                failureActions.lpsaActions = lpsaActions;
            }

            if (txtProgram.Enabled)
                failureActionUpdate.lpCommand = txtProgram.Text.Trim() + " " + txtCommandlines.Text.Trim();

            if (btnBrowse.Enabled)
            {
                failureActionUpdate.lpRebootMsg = failureActions.lpRebootMsg;
                failureActionUpdate.dwResetPeriod = failureActions.dwResetPeriod;
            }

            if (ServiceManagerWindowsWrapper.ApiChangeServiceConfig2(
                                            serviceName, failureActionUpdate))
            {
                Logger.Log("ServiceRecoveryPage:OnApply():ApiChangeServiceConfig2()");
                //return false;
            }

            if (lpsaActions != IntPtr.Zero)
                Marshal.FreeHGlobal(lpsaActions);

            return true;
        }