timer - if specific time passed show messagebox in C# -
so, want this: if specific time passed (for example 9 hours) loading form, want show messagebox said "9 hours passed". code this:
public partial class form1 : form { stopwatch stopwatch = new stopwatch(); public form1() { initializecomponent(); stopwatch.start(); } private void button1_click(object sender, eventargs e) { double sec = stopwatch.elapsedmilliseconds / 1000; double min = sec / 60; double hour = min / 60; if (hour == 9.00d) { stopwatch.stop(); messagebox.show("passed: " + hour.tostring("0.00")); } } }
and problem don't know write part of code:
if (hour == 9.00d) { stopwatch.stop(); messagebox.show("passed: " + hour.tostring("0.00")); }
so, write code? if have better way of doing this, please show me.
what people not appreciating is unlikely double hours
9.00! why not ask timer fire once, after time want, 9 hours.
timer timer; public form1() { initializecomponent(); timer.tick += timer_tick; timer.interval = timespan.fromhours(9).totalmilliseconds; timer.start(); } void timer_tick(object sender, eventargs e) { timer.stop(); messagebox.show("9 hours passed"); }
Comments
Post a Comment