Danke, funktioniert perfekt!
Bonjour,
ich versuche aktuell in einem Forms-Programm die Stunden per DateTime permanent zu vergleichen, bis um 04:00 Uhr und das um 04:00 Uhr dann eine Aktion ausgeführt wird.
Das Problem:
Es scheint so oft und so schnell zu überprüfen, dass es das Programm auf Inaktiv setzt und nichts mehr funktioniert =\
Wie kann ich jetzt verhindern, dass es nicht in den Inaktiv Status geht aber trotz dessen noch überprüft und um Punkt 04:00 Uhr meine Aktion ausführt?
Die Aktion funktioniert, hab ich schon ausprobiert.
DateTime now = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
DateTime then = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 4, 00, DateTime.Now.Second);
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
int compareValue = now.CompareTo(then);
while(compareValue != 0)
{
timer1.Start();
timer1.Tick += new EventHandler(timer_Tick);
}
if (compareValue == 0)
{
//AKTION
}
}
}
void timer_Tick(object sender, EventArgs e)
{
int compareValue = now.CompareTo(then);
}