Note that there are some explanatory texts on larger screens.

plurals
  1. POAccurate, Multithreaded Equivalent for System.Timers.Timer in Silverlight?
    text
    copied!<p>I have the following code using System.Timers.Timer in a WPF application and wish to port to Silverlight. The timer is used in WPF to poll data updates for a high-performance visualization component, hence the UI thread is running flat out. </p> <pre><code> private System.Timers.Timer _timer; private const int TimerInterval = 10; private void Start() { _timer = new Timer(TimerInterval); _timer.Elapsed += OnTick; _timer.AutoReset = true; _timer.Start(); } private void OnTick(object sender, EventArgs e) { } // ... </code></pre> <p>The specific requirement is as follows:</p> <blockquote> <p>I have a WPF App using System.Timers.Timer which reads / buffers data from external hardware every 10ms and preprocesses, before loading into a visualization component. The client wishes to see a demo of a Silverlight version of this component to view the data at the same rate offline. </p> <p>To replicate the same behaviour I have created a demo where dummy data is read from an embedded resource every 10ms and pushed into the visualization component. DispatcherTimer will tick but since the UI is working hard, the GUI stutters. The GUI can handle the update rate, just the reading from file/pre-processing of this data which needs to be multi threaded at a rate as close as possible to 100Hz.</p> </blockquote> <p>In short, I expect a timer to fire periodically until stopped and as close to 10ms as possible regardless of OnTick handler duration. The Ontick handler should also occur on a threadpool (or background) thread to allow data reads/processing in a multithreaded fashion.</p> <p>I see there is a System.Threading.Timer in Silverlight but am unsure of the usage and how it may differ to the Timers.Timer version.</p> <p>Can anyone comment on a good port to Silverlight for the above Timer code or a workaround to achieve the above requirement?</p> <p>Comments/Suggestions welcome. </p> <p>Best regards, </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload