Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i was trying to insert data into database using sql query ,while executing the method in Form1_Load,Button,etc everything is going fine, but when i try to execute this method into the timer eventhandler, the timer execute the query 2 times

What do i need is the following:-

1.Why is this happening
2.A solution for this issue

Thanks,

Regards,

Snake.
Posted

Well, I'm not sure if you want help, because if you did, you'd surely post some code ? Your timer will keep firing until you stop it. So, stop the timer firing as the first line of your event ( it also has a property as to if it will fire more than once, but I always turn them off in the event, to be sure ). But, I am guessing as to what the cause is, based on the lack of info you provided.
 
Share this answer
 
Comments
ngthtra 23-Jun-11 22:01pm    
can you post some code?
I don't know howw you code. but you can reference the following:
int flag =0;
code into evetn timer:
if (flag=0)
{
// execute your query
flag = 1;
}

I hope that this way will usefull for you.

Good lucky!
Christian Graus 23-Jun-11 22:13pm    
Why did you comment to me and not the OP ? Your code doesn't look remotely useful in any case, but....
snake1 23-Jun-11 22:38pm    
i dun think that's gonna work , i'm doing an operation every 1 minute,i want the program to execute the method 1 time every minute but the timer execute it 2 times every 1 minute
Christian Graus 24-Jun-11 0:02am    
You've still not posted code, so I doubt you really want help. I suspect then that you've assigned the tick event twice, so it's called twice. Again, we're guessing because you don't want help enough to show us your code.
try moving your method out of the timer tick event

C#
Timer MyTimer = new Timer();

MyTimer_Tick(object sender, EventArgs e)
{
MyTimer.Enabled = false;
DoMyAction();
}

void DoMyAction()
{
//do you actions here
MyTimer.Enabled = true;
}
 
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