Hello,
I am writing a program (for fun as well as for practical uses) that will allow me to keep track of several projects I am working on and how long I have spent working on each.
My program has a class "Project" which has the following variables:
Private projectID As Integer ' Project's unique identifier
Private projectTitle As String ' Project's title
Private description As String ' Project's description
Private elapsedTime As UInteger = 0 ' Total time elapsed for the project so far
Private active As Boolean ' Whether or not the project is active
Private entries As New List(Of Entry) ' A List of all entries (start-stop intervals) for this project
When active = true
, the elapsedTime
should increment by 1 every second. I've thought of two ways of doing this:
1) Create a timer in the main form that checks every tick for which projects are active. If the project is active, increment its elapsedTime. However, this would mean that the count would be off by milliseconds if the user does not activate the project exactly on the tick (which is not likely). Now, I know that this error is a negligible amount of time, but since I'm a bit of a perfectionist, and just for the sake of satisfying my curiosity of how it's done, I propose method 2:
2) Add a timer to class Project so that every Project object has its own timer that it can enable and disable, thus eliminating the time inaccuracy.
Unfortunately, I can't figure out how to do this. How do I add a timer to the Project class, and how do I handle the ticks? Is this even possible? Is there a better way to accomplish this?
Thanks!
- Z