user3478065
user3478065

Reputation: 35

how to display a message box when timer elapses in c#

I gave my time interval as 100. when the timer elapsed the message box is displayed but my screen is flooded with message boxes. How should i stop it with one message box indicating timer elapsed. Here's my code... Can you guide me where to give stop timer...

namespace timer1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Timer t = new Timer();
            t.Interval = 100;
            timer1.Enabled = true;
            timer1.Tick += new System.EventHandler(OnTimerEvent);

        }
        private void OnTimerEvent(object sender, EventArgs e)
        {

            MessageBox.Show("time over");

        }

    }
}

Upvotes: 0

Views: 2306

Answers (1)

ChrisB
ChrisB

Reputation: 498

I guess (as you don't provide code), in the Interrupt Service Routine:

public void YourTimer_Tick(object sender, EventArgs e)
{
      YourTimer.Stop();
      MessageBox.Show("You message...");
}

Upvotes: 1

Related Questions