While working on the development of SciChart one of the challenges has been simultaneously developing a WPF and Silverlight version of this high performance chart using as much of the same codebase as possible. While with the advent of Silverlight versions 3.0, 4.0 and 5.0 sharing code between Silverlight and WPF is now far easier, however it is still fraught with issues. Silverlight is inherently a subset (with extra bits) of WPF and there often comes a point where a simple class that you rely on in WPF doesn't exist in Silverlight.

One of the minor issues faced in writing dual deployed code was to use a multi-threaded Timer with the same API and System.Timers.Timer. Silverlight has the DispatcherTimer however in the specific usage it was necessary to fire accurately and on a background thread, since the UI is running flat out. 

Below is a first attempt at a drop-in replacement. Note it doesn't do synchronisation, although I am sure it wouldn't be too difficult to add given the availability of the Dispatcher in Silverlight!

namespace System.Timers
{
	/// 
	/// Drop in Silverlight compatible replacement for the System.Timers.Timer
	/// Doesn't do synchronisation
	/// 
	public class Timer
	{
		private readonly uint _interval;
		private System.Threading.Timer _internalTimer;
		private const uint MaxTime = (uint)0xFFFFFFFD;

		public event EventHandler 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);
			}
		}
	}
}

The second issue was finding a drop-in replacement for Stopwatch. This little class is excellent for debugging performance and micro-profiling. Below find a Silverlight compatible replacement for this class which you can drop in to your SL projects.

namespace System.Diagnostics
{
    /// 
    /// Stopwatch is used to measure the general performance of Silverlight functionality. Silverlight
    /// does not currently provide a high resolution timer as is available in many operating systems,
    /// so the resolution of this timer is limited to milliseconds. This class is best used to measure
    /// the relative performance of functions over many iterations.
    /// 
    public sealed class Stopwatch
    {
        private long _startTick;
        private long _elapsed;
        private bool _isRunning;

        /// 
        /// Creates a new instance of the class and starts the watch immediately.
        /// 
        /// An instance of Stopwatch, running.
        public static Stopwatch StartNew()
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            return sw;
        }

        /// 
        /// Creates an instance of the Stopwatch class.
        /// 
        public Stopwatch() { }

        /// 
        /// Completely resets and deactivates the timer.
        /// 
        public void Reset()
        {
            _elapsed = 0;
            _isRunning = false;
            _startTick = 0;
        }

        /// 
        /// Begins the timer.
        /// 
        public void Start()
        {
            if (!_isRunning)
            {
                _startTick = GetCurrentTicks();
                _isRunning = true;
            }
        }

        /// 
        /// Stops the current timer.
        /// 
        public void Stop()
        {
            if (_isRunning)
            {
                _elapsed += GetCurrentTicks() - _startTick;
                _isRunning = false;
            }
        }

        /// 
        /// Gets a value indicating whether the instance is currently recording.
        /// 
        public bool IsRunning
        {
            get { return _isRunning; }
        }

        /// 
        /// Gets the Elapsed time as a Timespan.
        /// 
        public TimeSpan Elapsed
        {
            get { return TimeSpan.FromMilliseconds(ElapsedMilliseconds); }
        }

        /// 
        /// Gets the Elapsed time as the total number of milliseconds.
        /// 
        public long ElapsedMilliseconds
        {
            get { return GetCurrentElapsedTicks() / TimeSpan.TicksPerMillisecond; }
        }

        /// 
        /// Gets the Elapsed time as the total number of ticks (which is faked
        /// as Silverlight doesn't have a way to get at the actual "Ticks")
        /// 
        public long ElapsedTicks
        {
            get { return GetCurrentElapsedTicks(); }
        }

        private long GetCurrentElapsedTicks()
        {
            return (long)(this._elapsed + (IsRunning ? (GetCurrentTicks() - _startTick) : 0));
        }

        private long GetCurrentTicks()
        {
            // TickCount: Gets the number of milliseconds elapsed since the system started.
            return Environment.TickCount * TimeSpan.TicksPerMillisecond;
        }
    }
}