0

Well, I'm trying to make an timer which will close the app after 10sec. but i'm just almost started to learn c#, also sorry for my english. So when i make the

Timer7.start();
Timer7.Enabled();
Timer7.Interval = 10000; //10sec.?

And the Timer7 meaning.

private void timer7_Tick(object sender, EventArgs e)
{
    //po nebuvimo intiko close app
    Application.Exit();
    MessageBox.Show("Hello");
    timer7.Stop();
}

And I do get this error:

Object reference not set to an instance of an object

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • has the `timer7` variable exist? – david Jul 13 '18 at 07:47
  • 1
    Application.Exit(); should be last line – puneet Jul 13 '18 at 07:47
  • When do you initialize `Timer7`? – fredrik Jul 13 '18 at 07:48
  • What do you mean intialize? –  Jul 13 '18 at 07:49
  • This [MSDN article on Timer will be your best help - Timer Class](https://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx#Anchor_7). it includes an example of how to setup and use the Timer, and also how to act when the Timer event fires. – JayV Jul 13 '18 at 07:49
  • Where do you define `Timer7` and set it to an instance of whichever type it is declared as? – fredrik Jul 13 '18 at 07:49
  • I created The Timer7 in the form –  Jul 13 '18 at 07:52
  • I have about 20 timers done, in other forms, but they do work fine, i don't know whats the reason now. –  Jul 13 '18 at 07:52
  • @ByByUostykLoxas think you will have to post more code - are you trying to do this in another class or in the class of the Form istelf? (can't see anything on the screenshot) – dunkleosteus Jul 13 '18 at 08:23

0 Answers0