Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer remaining active after the form is closed 1

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello,

[2005]

I have form that uses a timer control. The user can stop, start and reset this timer. The idea of this timer is to log how long a engineer has taken to complete a specific job. The user will stop the timer by clicking a button on the form.

However, the problem is that the user can close the form and when they do the timer will automatically stop.

I am looking for a solution what will allow the timer to function after form has been closed and when the form is re-opened no time has been lost.

I know that the timer will run in the UI thread, so is it worth creating another thread for the actual timer control?

This is a mdi application, is it a better solution to have the timer control placed on the parent?

Many thanks for any suggestions and ideas,

Steve
 
Dear mister steve1rm,

Two solutions spring to mind.

1. I think what you need is a bit of MVC (actually you always should use MVC). So you need A controller class that holds a reference to the form and to the timer. This controller class will open your form and deal with any events coming from the form. The controller also holds a reference to the model for example the engineer object. The timer will keep ticking even if the form is closed. I think you will need a timer object that keeps the time (model). The view will show the time passed by asking the controller the time it has in the timer object or by implementing the observer pattern and letting the model say to the view to update itself. Seems complicated? No not really. The controller should only close on itself when the app closes.

2. When the timer starts you save the starting time. When the form closes you just stop the timer. When the form opens again you still have the starting time so you can easily know how much time has passed since then and then you continue counting down. Seems easy enough.

Hope this was helpfull. Keep on ticking.



Christiaan Baes
Belgium

"My old site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top