I have a message box show that I wanted to pop up at a given time.
I have set up the code below, but it fires like 9 times and I get 9 message boxes - all the same. I assume this was due to the ticks being on the second :00 for 9 ticks (given that my clock interval is set to 100) - so I tried to work in an interval break
That didn't work, so tried a bool that I could change once the message box had shown, but that didn't work either.
As you can imagine, trying to debug this using breakpoints is pretty tough, I have to change my PC clock each time and of course, the moment it stops for the break point, the next tick is several seconds later and bypasses the code entirely as it isn't 23:55:00 anymore...
I just wondered if anyone had a neat workaround for this type of thing a way to fire off the message box just the once on the tick.
Code for the bool is below but as I say, it doesn't work.
Just so you know, I tried the following as well:
That didn't work either.
I have set up the code below, but it fires like 9 times and I get 9 message boxes - all the same. I assume this was due to the ticks being on the second :00 for 9 ticks (given that my clock interval is set to 100) - so I tried to work in an interval break
C#:
System.Timers.Timer t = new System.Timers.Timer();
t.Interval = 2000;
t.Start();
t.Stop();
That didn't work, so tried a bool that I could change once the message box had shown, but that didn't work either.
As you can imagine, trying to debug this using breakpoints is pretty tough, I have to change my PC clock each time and of course, the moment it stops for the break point, the next tick is several seconds later and bypasses the code entirely as it isn't 23:55:00 anymore...
I just wondered if anyone had a neat workaround for this type of thing a way to fire off the message box just the once on the tick.
Code for the bool is below but as I say, it doesn't work.
C#:
bool isOpen = false;
if (time == "23:55:00")
{
if (isOpen == false)
{
if (File.Exists(EX1))
{
MessageBox.Show($"At 11:59pm the application will delete ALL data files, including the excel {EX1}");
isOpen = true;
}
else
{
MessageBox.Show("At 11:59pm the application will create an Excel.");
isOpen = true;
}
}
else
{
}
}
Just so you know, I tried the following as well:
C#:
if (time == "23:55:00" && isOpen == false)
{
//same code as above
}
That didn't work either.
Last edited: