Click here to Skip to main content
13,050,450 members (80,683 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 1:20am
Updated 2-Jul-13 1:21am
ThePhantomUpvoter 2-Jul-13 7:23am
timer.Enabled = false;
ryanb31 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2017
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