Click here to Skip to main content
15,916,215 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used a windows form c# and I want to put a timer to close dialog after 30 seconds..
this.Load += new System.EventHandler(this.Form1_Load);

I have in main:
namespace WindowsFormsApplicationDymoNew
    static class Program
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)

           // string t = "";

            Form1 y = new Form1();




What I have tried:

Now I don't know how I can add time to this code
Updated 31-Mar-23 5:03am

1 solution

You have to set up a timer like this.
Googling produced many results "close windows form using timer"

using Timer = System.Windows.Forms.Timer;

 private void Form1_Load(object sender, EventArgs e)
            // Timer to Close App
            Timer MyTimer = new Timer();   
            MyTimer.Interval = (1 * 60 * 1000); // 1 mins
            MyTimer.Tick += new EventHandler(timer1_Tick);

        private void timer1_Tick(object sender, EventArgs e)

            label9.Text = (int.Parse(label9.Text) - 1).ToString();
            if (int.Parse(label9.Text) == 0)  //if the countdown reaches '0', we stop it

            //  MessageBox.Show("The form will now be closed.", "Time Elapsed");



Share this answer
Member 14594285 31-Mar-23 11:14am    
thanks, very useful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900