Share via


C# Timers do they cause the application to slow down.

Question

Thursday, October 30, 2008 9:45 PM

 if I use three or four timers on each of my forms is that going to have an impact on the performance of my application?

I want to use timer when the form opens to increase the opacity over about 1/2 second.

I have three images in picture boxes that when clicked will set another corresponding picture box to visible for 1 second controlled by a timer.

Is this a bad way of doing this?

Should i dispose of timers when not in use or is setting enabled to false acceptable? Does closing a form dispose of the timers in use on it? If i close a form and then dispose the form does it dispose of everything in the form?

All replies (3)

Friday, October 31, 2008 1:23 PM âś…Answered

 

The Riviera Kid said:

 if I use three or four timers on each of my forms is that going to have an impact on the performance of my application?

The timers themselves won't have much impact on your application its what you do in those timers, if you run an atomic particle simulation every 50 ms on a timer yeahh you'll notice if like you you use 'm for simple stuff i doubt you will notice.

The Riviera Kid said: I want to use timer when the form opens to increase the opacity over about 1/2 second.

I have three images in picture boxes that when clicked will set another corresponding picture box to visible for 1 second controlled by a timer.

Is this a bad way of doing this?

Not realy flipping a visible property doesn't take that much resources
 

The Riviera Kid said: Should i dispose of timers when not in use or is setting enabled to false acceptable?

Setting enabled to false is prefectly acceptable.

The Riviera Kid said: Does closing a form dispose of the timers in use on it? If i close a form and then dispose the form does it dispose of everything in the form?

Stuff on the form yes so your timers will be nicely nicely be disposed off, howeover if you programatically created some long lived objects (a thread for instance) you might want to write a little clean up code for those.


Thursday, October 30, 2008 9:55 PM | 1 vote

 You may consider using a StopWatch class for this since it appears you have a few one time events that take place only when the form is opened. Timers will not impact performance, neither StopWatch. Close the form--timers are gone. Dispose of them when not needed. Keep it in mind that the GC may take time to actually remove them. It is possible it will kill them if you leave them alone unused for long time without your assistance.


AlexB


Thursday, October 30, 2008 10:21 PM | 1 vote

Timers are usually implemented by the compiler as a background thread.  Once you disable them, they should not be a problem.

Rudedog   =8^D


Mark the best replies as answers. "Fooling computers since 1971."