AutoWakeUp.MainForm.buttonGoToSleepAndWait_Click C# (CSharp) Method

buttonGoToSleepAndWait_Click() private method

private buttonGoToSleepAndWait_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void buttonGoToSleepAndWait_Click(object sender, EventArgs e)
        {
            SetControlEnabled(false);

            DateTime now = DateTime.Now;

            DateTime wake_up_time = new DateTime(now.Year, now.Month, now.Day, dateTimePickerWakeUpTime.Value.Hour, dateTimePickerWakeUpTime.Value.Minute, dateTimePickerWakeUpTime.Value.Second, DateTimeKind.Local);
            if (wake_up_time < now)
            {
                wake_up_time = wake_up_time.AddDays(1.0);
            }

            DateTime suspend_time = new DateTime(now.Year, now.Month, now.Day, dateTimePickerRestTime.Value.Hour, dateTimePickerRestTime.Value.Minute, dateTimePickerRestTime.Value.Second, DateTimeKind.Local);
            if (suspend_time < now)
            {
                suspend_time = suspend_time.AddDays(1.0);
            }

            if (suspend_time < wake_up_time)
            {
                MessageBox.Show("Wait Until Time should be later than Wake Up Time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                SetControlEnabled(true);
                return;
            }

            Func<Action, Action> get_invoker = (action) =>
            {
                return () =>
                {
                    this.BeginInvoke(action);
                };
            };

            SystemActions.WaitThenDoStuff(wake_up_time, get_invoker(new Action(WakeUpStuff)));
            SystemActions.WaitThenDoStuff(suspend_time, get_invoker(new Action(SuspendStuff)));

            SystemActions.SystemSleep();
        }