Is it ok to have 5 dispatcherTimer in one wpf application

Kalpana 291 Reputation points
2020-09-23T07:42:08.623+00:00

Hi,

I am a beginner and I have this requirement to create a timer based application in WPF. As the project grows, there are requirements of fitting many dispatchertimers into the application.

As of now, I have one dispatcherTimer to show the time in one textbox. That of course is at every millisecond.
The second dispatcherTimer executes a stored procedure every millisecond to check if there are values in the sql table. If there are new values, the colour of the ellipse in the wpf window changes.
The third one, executes stored procedure to do a calculation of some rows in the table. Again, the textbox is updated with those values.

Something is not right here.

Now, I have a requirement of displaying graphs based on the datatable ( datatable values retrieved using stored procedure ). This has to happen at 7am and at 7pm everyday. I just feel like, I am using so many dispatcherTimers.

Am I using the dispatcherTimer correctly...?
Please advice.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,781 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,326 Reputation points
    2020-09-23T07:59:34.767+00:00

    Hi Kalpana,
    each timer produce additional overhead. To reduce the number of timers you can use one timer with list of activities. Sort the list you can detect the next interval. Execute each activity asynchronously (Task object).

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.