using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.ComponentModel; namespace CountdownTimer { class TimerSource : INotifyPropertyChanged { int _secs = 900; Timer _timer; public event PropertyChangedEventHandler PropertyChanged; void Notify(string propName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propName)); } public delegate void TimedOutHandler(); public event TimedOutHandler TimedOut; public string Time { get { int mins, secs; mins = Math.DivRem(_secs, 60, out secs); return String.Format("{0}:{1:D2}", mins, secs); } set { // XXX handle string form mm:ss _secs = Int32.Parse(value); } } public void Start() { _timer = new Timer(this.tick, null, 0, 1000); } private void tick(object unused) { _secs--; Notify("Time"); if (_secs == 0) { _timer.Dispose(); _timer = null; if (TimedOut != null) TimedOut(); } } internal void SetTime(int secs) { _secs = secs; } } }