Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As it happens, I used the System.Threading.Timer and wrapped it to create a similar API to the Silverlight Timer. This helps in my situation as I am dual deploying code to WPF and SL, hence was looking not only for a functional equivalent but ideally code I could use in both scenarios. </p> <p>The below is tested as working but doesnt provide all the features of System.Timers.Timer (such as synchronisation). I'm sure it wouldn't be too difficult to add using the Dispatcher if anyone is so inclined!</p> <p>I have <a href="http://goo.gl/ILmFK" rel="nofollow">blogged about this here</a> (as well as a drop-in replacement for Stopwatch).</p> <p>Thank you for your comments &amp; suggestions anyway, they are very much appreciated. </p> <p>Best regards, </p> <pre><code>namespace System.Timers { /// &lt;summary&gt; /// Drop in Silverlight compatible replacement for the System.Timers.Timer /// Doesn't do synchronisation /// &lt;/summary&gt; public class Timer { private readonly uint _interval; private System.Threading.Timer _internalTimer; private const uint MaxTime = (uint)0xFFFFFFFD; public event EventHandler&lt;EventArgs&gt; Elapsed; public Timer(uint interval) { _interval = interval; } public bool AutoReset { get; set; } public void Start() { Stop(); _internalTimer = CreateTimer(); } public void Stop() { if (_internalTimer != null) { _internalTimer.Change(MaxTime, MaxTime); _internalTimer.Dispose(); _internalTimer = null; } } private Threading.Timer CreateTimer() { var timer = new System.Threading.Timer(InternalTick); timer.Change(_interval, AutoReset ? _interval : MaxTime); return timer; } private void InternalTick(object state) { var handler = Elapsed; if (handler != null) { handler(this, EventArgs.Empty); } } } } </code></pre>
 

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