locked
How to create Timer in C#

    Question

  • Hi,

    Could anyone please tell me what are the similar events in C# for C's SetTimer and KillTimer?

    Basically, I want to set the timer that should generates WM_TIMER win32 message every 5 seconds.

    I tired using System.Timers.Timer and System.Windows.Forms.

    Timer but it doesn't generate the WM_TIMER events.

    Also don't want function like below but I already overrided WndProc method so I just need to put WM_TIMER switch case inside.

    private Timer timer;  
     
    private void Form1_Load(object sender, EventArgs e)  
    {  
        timer = new Timer();  
        timer.Interval = 60000;
        this.timer.Tick += new EventHandler(timer_Tick);  
    }  
     
    private void button1_Click(object sender, EventArgs e)  
    {  
        timer.Enabled = !timer.Enabled;  
    }  
     
    void timer_Tick(object sender, EventArgs e)  
    {  
        // Do something...  

    Thanks, Megha
    • Edited by CSharpLeader Thursday, July 23, 2009 4:43 PM typo
    Thursday, July 23, 2009 4:42 PM

Answers

All replies