private void btnRunTimeAdd_Click(object sender, EventArgs e) { var timeToRun = new TimeToRun(_job.ScheduleId, dtpRunTime.Value); _job.Schedule.TimeToRun.Add(timeToRun); dgvRunTime.DataSource = _job.Schedule.TimeToRun.OrderBy(x => x.Time).ToList(); }
public void CheckAndRun() { var now = DateTime.Now; /* * if (TimeToRun <= now) * { * while (TimeToRun < now) * TimeToRun += Interval; * if (Action != null) * try * { * Action(); * } * catch { * } * } * if (TimeToRun == null || TimeToRun < now) * TimeToRun = now; * */ var date = TimeToRun.AddSeconds(Interval.Seconds); var v = date.CompareTo(now); bool b = false; if (v == 0) { MessageBox.Show("" + v); Action?.Invoke(); b = true; } }
private void setupControl(TimeToRun when, bool clearForm) { if (!clearForm) comboBox1.SelectedItem = when.ToString(); switch (when) { case TimeToRun.Yearly: if (!clearForm) dtSelectTime.Value = new DateTime(_options.Year, _options.Month, _options.Day); else { dtSelectTime.Value = DateTime.Now; dtMonth.Visible = false; cboWeekDay.Visible = false; } Height = 147; dtSelectTime.Visible = true; break; case TimeToRun.Weekly: Height = 150; cboWeekDay.Visible = true; if (!clearForm) cboWeekDay.SelectedIndex = _options.Day; else { dtMonth.Visible = false; dtSelectTime.Visible = false; cboWeekDay.SelectedIndex = 1; } break; case TimeToRun.Monthly: Height = 311; cboWeekDay.Visible = false; dtMonth.Visible = true; dtMonth.MinDate = dtMonth.MinDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); dtMonth.MaxDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, daysInCurrentMonth); if (!clearForm) { int dayInMonth = _options.Day > daysInCurrentMonth ? daysInCurrentMonth : _options.Day; Contract.Assume(dayInMonth > 1); dtMonth.SetDate(new DateTime(DateTime.Now.Year, DateTime.Now.Month, dayInMonth)); } else { dtMonth.SetDate(DateTime.Now); } break; case TimeToRun.Daily: Height = 147; dtMonth.Visible = false; cboWeekDay.Visible = false; dtSelectTime.Visible = false; break; } }