Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I develop serial port data receive software in c# window application.

It's work properly but my question is i use timer control in my project and i want when i press start button timer is start and i want to wait 200 millisecond if data not receive then stop timer in before 200 ms then stop timer and again start timer and do this same process till some time. so i don't know how to wait for 200ms and stop timer i am familial with time i use it lots of time but now like this.
Please solve this.
Posted

You can use thread to wait for some time.

C#
Thread.Sleep(200) //200 : Time in milisecond to wait
 
Share this answer
 
Comments
Amir Mahfoozi 19-Dec-11 5:04am    
+5
jaideepsinh 19-Dec-11 5:13am    
I want timer gap not time interval.
hi,

When you start your timer you can put timer inteval and specify the time.

C#
timer1.Interval = 200;
 
Share this answer
 
v2
Comments
jaideepsinh 19-Dec-11 5:12am    
i want time gap not timer interval.
You can specify time interval
timer1.interval = 1000; ///millisecond

you have methods like [timer1.start] and [timer1.stop] which can be used to startand stop timer when ever you required
 
Share this answer
 
Hi,

show this example:

C#
public partial class FormWithTimer : Form
    {
        Timer timer = new Timer();

        public FormWithTimer()
        {
            InitializeComponent();

            timer.Tick += new EventHandler(timer_Tick); // It better to do this whith double Tab Key
            timer.Interval = 1;             
            timer.Enabled = true;           
        }

        void timer_Tick(object sender, EventArgs e)
        {
            //Your Code
        }
    } 
 
Share this answer
 
Comments
jaideepsinh 19-Dec-11 8:14am    
void timer_Tick(object sender, EventArgs e)
{
//I write my code for start and stop here
}
i use my counter and use it for stop and start timer.
public partial class FormWithTimer : Form
{
Timer timer = new Timer();

public FormWithTimer()
{
InitializeComponent();

timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 1;
timer.start();
}
public static int counter;
void timer_Tick(object sender, EventArgs e)
{
counter++;
if(counter>200)
timer.stop();
counter=0;
timer.start();
timer.interval=1;
.
.
continue.......

}
}
 
Share this answer
 

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