Which timer to use and how?

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
This app is a little more complicated that this but I have pared things down to the basics.
The application has a class that implements the IBindingListinterface so I can bind a list of this class to a datagridview. This datagridview has custom progress bar columns that illustrate the progress of a task.

I have a list of tasks that I need to show the progress of. These
tasks are started at various times i.e.

taskList[0].StartTime = 10:00;
taskList[1].StartTime = 10:30;
taskList[2].StartTime = 11:30;

I then have a System.Timers.Timer instance that iterates through each list item in the list and calculates the elapsed timespan converts it to an integer and displays the progress

foreach (Task t in taskListBindingSource.List)

// Calculate the different timespans in the list, convert them to an integer and display in the datagrid.


I am quite pleased that the program works but am most dipleased with the foreach loop because that seems dirty to me. The program also hangs frequently after running for 30 mins+ which is unacceptable because I need it running for days at a time. The System.Threading.Timer seems perfect because you can pass the object (or task) into the method that then displays the progress at intervals. I have tried this and found it horribly complicated and confusing, and worse still, you have unpredicable behaviour, i.e. it will start and then stop randomly and you can’t debug it.

I feel this is quite a generic problem that a lot of users should be acquainted with, so any pointers would be appreciated.



More...

View All Our Microsoft Related Feeds
 
Back
Top