我在 C# 中有一个函数,它一开始将 GUI DateTimePicker 对象的值设置为今天的日期(时间 = 午夜),然后执行其他操作。通过 GUI 按钮执行时,函数 (DBIO_Morning) 运行良好。但是,通过定时操作执行:
private void SetupTimedActions()
{
...
DateTime ref_morning = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 16, 0);
if (DateTime.Now < ref_morning)
At.Do(() => DBIO_Morning(), ref_morning);
...
}
它在第二行失败:
private void DBIO_Morning()
{
DateTime date_current = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0);
DTPicker_start.Value = date_current;
...
}
( At.Do 对象来自这里的第三个答案:C# execute action after X seconds)