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 Have a problem with my current project ,

I have a desktop application that run in a pc server ,
the application should be run every seconds,

I have to create a method that run periodically ,

the method run every 2 seconds
, There is no problem when the application running during a day ,but after two days ,the application would be not responding

What I have tried:

timer1.Enabled = true;
           timer1.Start();
           timer1.Tick += (source, es) =>
           {
               timer1.Interval = 1000; GetdataMachine();label1.Text = DateTime.Now.ToString("dd MMMM yyyy hh:mm:ss");
           };
Posted
Updated 7-Apr-21 19:53pm

1 solution

Your Interval is 1 second, not 2 - and that may be contributing to the problem.
I would assign the Tick handler before I start the Timer personally but it shouldn;t cause a problem.

We can't help you fix this - we have no idea what your GetdataMachine method does - but if it takes longer than one second to execute at any time, then it's possible that your message queue is filling up and UI updates no longer happen, so your app appears to freeze and stop working.

Start by adding logging to your Tick handler: use a Stopwatch Class (System.Diagnostics) | Microsoft Docs[^] to time the event handler, and log that to a file for review after it stops working, along with the current date and time.

See if at any point the event handler is taking too long to execute after it fails.
 
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