c# - Using Timer only once -


I want to use the timer only once after 1 second of the initialization of my main form, I thought " Hello World "will be a message box, but in reality a new message box" Hello World "says in every second.

Why so? I had put t.Stop () in the tick code, besides, do I need to settle the timer to avoid memory leak?

  timer t = new timer (); T.Interval = 1000; T. Tick ​​+ = Representative (System.Object o, System. EventVargas E) {Message Box. Show ("Hello World"); T.Stop (); }; T.Start ();  

Please help and show that what is the best way to do this? Thank you.

change MessageBox.Show ("Hello World"); T.Stop (); With t. Stop it (); message box. Show ("Hello World"); . Because you are not pressing on time, the timer has already rested and you never reached the stop code.


Comments