Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
I am using timer in c# to send command to hardware at once, I don't want to create a button to send command but when i run start program it has to send command automatically, so for that purpose I have created timer to send command to via usb serial port. But the problem is it is sending every second so can anyone help me how to send only once when program starts. I don't want to send every second.
public partial class FormWithTimer : Form
        Timer timer = new Timer();
        public FormWithTimer()
            timer.Tick += new EventHandler(timer_Tick); // Every Time timer ticks, timer_Tick will be called
            timer.Interval = (1000) * (1);              // Timer will tick every second
            timer.Enabled = true;                       // Enable the timer
            timer.Start();                              // Start the timer
        void timer_Tick(object sender, EventArgs e)

Any suggestion?
Thanks in advance...
Posted 2-Jul-13 2:20am
Edited 2-Jul-13 2:21am
ThePhantomUpvoter at 2-Jul-13 7:23am
timer.Enabled = false;
ryanb31 at 2-Jul-13 7:57am
You need to disable your timer. But if you are only sending it once why not when your app starts instead of using a timer?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

        void timer_Tick(object sender, EventArgs e)
Why are you using a timer?

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

  Print Answers RSS
0 /\jmot 230
1 Zoltán Zörgő 210
2 Peter Leow 145
3 Sergey Alexandrovich Kryukov 115
4 _Asif_ 108
0 Sergey Alexandrovich Kryukov 9,353
1 OriginalGriff 6,881
2 Peter Leow 4,577
3 Zoltán Zörgő 4,129
4 Richard MacCutchan 2,882

Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100