Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, August 16, 2010 5:32 PM
How can i make a button e clicked every 30 seconds
I think i can use a timer but not sure how
The timer needs to click the button every 30 seconds
Thanks
All replies (11)
Monday, August 16, 2010 6:15 PM ✅Answered | 2 votes
Set a timer with an interval of 30000 milliseconds.
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 30000;
timer.Tick += new EventHandler(timer_Tick);
And define a method where you make the button perform a click.
static void timer_Tick(object sender, EventArgs e)
{
button1.PerformClick();
}
Thursday, August 19, 2010 4:46 PM ✅Answered
I forgot to tell you to start the timer:
Timer tmr = new Timer();
tmr.Interval = 30000;
tmr.Tick += new EventHandler(tmr_Tick);
tmr.Start();
Monday, August 16, 2010 5:41 PM
Define a Time variable, then update time in begining and after each time your button clickied ,then compare now time- 30 sec with your variable Time ,if now time is bigger than now time, function can execute, or depend on what u want, you may want to disable whole button, then you should do this on a button....
Monday, August 16, 2010 6:01 PM
Not sure what you mean or how to do
Monday, August 16, 2010 7:12 PM
what ?!
u mean timer_Tick will be event of both timer, and the button ?!
Monday, August 16, 2010 7:20 PM
It will be the event handler of the timer method, and what it will do is tell the button that it was clicked. It's not an event of the button.
Monday, August 16, 2010 7:24 PM
Do you really want to click a button every 30 seconds or do you want to perform the operation that the Button performs when it's clicked... every 30 seconds?
Your handler for the Button click should be calling a method that does what you want. And you can call that same method on a timer that ticks every 30 seconds.
Tuesday, August 17, 2010 6:57 AM
I doesent seem do be working
i need the button to be click automatically every 30 second to update two databases that has to be updated with each other ... you can say its like a web service
Tuesday, August 17, 2010 4:31 PM
And what happens when you implement the suggestion provided here?
Thursday, August 19, 2010 9:41 AM
I tried this but when my program is in debug mode then i wait for 30 seconds and nothing happens dunno why?
private void btnUpdateNow_Click(object sender, EventArgs e)
{
btnInject.PerformClick();
btnInjectintoAccess.PerformClick();
lblstatus.ForeColor = Color.Green;
lblstatus.Text = "Updated";
lbltime.ForeColor = Color.White;
lbltime.Text = DateTime.Now.ToLongDateString();
if (lblstatus.Text == "Updated")
{
Timer tmr = new Timer();
tmr.Interval = 30000;
tmr.Tick +=new EventHandler(tmr_Tick);
}
}
private void tmr_Tick(object sender,EventArgs e)
{
btnUpdateNow.PerformClick();
}
Thursday, September 2, 2010 9:15 AM
I think only when i added tmr.Enabled = true ; then it worked but thats what i think