Flash vs Silverlight: Kit3D vs Papervision3D Example Flash vs Silverlight: Color Fill Toy
Jan 10

In Flash and Silverlight, there are many ways to call a method by a regular time interval. Today I will use a simple sample to illustrate their differences on the following methods:

  • Flash - flash.utils.Timer
  • Flash - Event.ENTER_FRAME
  • Silverlight - System.Windows.Threading.DispatcherTimer
  • Silverlight - CompositionTarget.Rendering

The samples are running with 10 FPS (Frame rate per second) and the timer interval is set to be 100 milliseconds.

Comparison

Flash implementation: 30 minutes
Silverlight implementation: 30 minutes (Implemented First)
What’s the difference?

  • Flash: Timer vs Enter Frame
  • Silverlight: Dispatcher Timer vs Composition Target

Source codes

Flash

Silverlight

Flash: Timer vs Enter Frame

(The result I described below may be varies in different browser or different OS)

Both of the method generated exactly the same count value. However, you will find that the number of handlers are called less than expected.

It is supposed for each second, the counter will be increased by 10. But the actual case is that the counter is less than the expected value as time goes by.

Silverlight: Dispatcher Timer vs Composition Target

I think Silverlight has more funny outcomes.

Firstly, the increment in Dispatcher Timer is far less than the value in that of Composition Target. (They are expected to be the same.)

Besides that, CompositionTarget.Tick will be stopped if the Application is not shown on the screen. Here is a simple trial, just scroll up your browser until the Application is completely moved out of the screen. Scroll back to the Application a while later. You will find that Dispatcher Timer will has a bigger value.

Shares and Enjoy~

Did you like this post?

Subscribe here:  

13 Responses to “Difference on Timer, Enter Frame, Dispatcher Timer and Composition Target”

  1. Vitor Canova Says:

    Incredible diference between size. 253 KB in Flash vesus 34 KB in Silverlight.

  2. Dennis Says:

    I am only getting 7 FPS on the flash

  3. admin Says:

    Some mistake when saving the FLA. The actual file size should be 10KB only.

  4. Fallon Massey Says:

    It appears that if you need a heartbeat in SL, you better use dispatchtimer, or a storyboard timer(if you need better accuracy), instead of the newer Composition Target.

    Composition Target is actually better than dispatch in accuracy, but not working if the control isn’t visible is horrible.

  5. Fallon Massey Says:

    Hey Terence,

    I liked your Grid Transition Rotator. For the Flash Version, would you consider making it grab images from the server?

    That would make it more generic and useful. Thanks.

  6. admin Says:

    Fallon Massey,

    Thanks for the suggestion. I am considering to launch a new site mainly for image rotators. More features, like the one you mentioned, will be added as well.

  7. Daniel Dowell Says:

    I rewrote your Flash implementation and for some reason I get much better results. The frame counter is updating perfectly while the timer lags a little behind (which is natural since Flash’s timers are only firing on the frame after the timer expires (and not on the exact millisecond)). I work with Flash daily and we use both timers and frame listeners and we have never seen the lag that you have in your application.

  8. Fallon Massey Says:

    Good idea, keep us informed.

  9. Flash vs. Silverlight | Silverlight made Simple - by Corey Schuman Says:

    [...] is showing the differences between Flash’s Enter frame and Silverlight Composition Target - http://www.shinedraw.com/mathematics/difference-on-timer-enter-frame-dispatcher-timer-and-compositio... Date January 12th, 2009 Filed in [...]

  10. Silverlight Cream for January 10, 2009 -- #481 Says:

    [...] SNow has his latest up … can you believe he’s up to 80?? .. this one is good info on clipping. Difference on Timer, Enter Frame, Dispatcher Timer and Composition Target Terence Tsang has another post up today, in this one the Silverlight is comparing DispatcherTimer [...]

  11. cisnky Says:

    @Vitor Canova Where did you get 253 KB? The swf file is 3kb.

    @Daniel Dowell The lag Shine gets is from setting the frame rate of the Flash movie to 10.

    @shine “It is supposed for each second, the counter will be increased by 10. But the actual case is that the counter is less than the expected value as time goes by.”

    If you want the timer event to be called every second then your timer constructor should say _timer = new Timer(1000); and not _timer = new Timer(1000/10);

    1000milliseconds = 1 second

    With the whole voting, I think you have more SilverLight developers on this blog then Flash :)

  12. Denis Says:

    CompositionTarget is not a timer! It shouldn’t be used as a timer. It is great that Microsoft shuts down rendering then silverlight control isn’t visible. This way it will use less CPU resources.
    SL does better job in timer department then Flash.

  13. Markus Johnsson Says:

    Can you explain why you would expect CompositionTarget.Rendering to be the same as DispatcherTimer.Tick?

    DispatcherTimer checks whether the given interval has elapsed before fireing its event. If there are any precision errors in your code the rate will drop or be boosted depending on the nature of the precision error. If you express the same timespan as Silverlight uses (probably a fixed number of milliseconds) you will get the same result from both.

    You also failed to mention that Silverlight is actually mutithreaded and you can fire timer events on background threads for processing of non GUI-stuff.

Leave a Reply