using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Threading.Tasks; using System.Windows; using DT2; namespace DT3 { public class UrlTesterModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; int size; int time; string url; DT2.UrlTester urlTester; public UrlTesterModel() { urlTester = new DT2.UrlTester(); IDictionary sw = new Dictionary(); urlTester.PageStart += url => { sw.Add(url, Stopwatch.StartNew()); }; urlTester.PageLoaded += (url, size) => { sw[url].Stop(); int time = (int)sw[url].Elapsed.TotalMilliseconds; Size = size; Time = time; sw.Remove(url); }; } public int Size { get { return size; } set { size = value; NotifyPropertyChanged(nameof(Size)); } } public int Time { get { return time; } set { time = value; NotifyPropertyChanged(nameof(Time)); } } public string Url { get { return url; } set { url = value; NotifyPropertyChanged(nameof(Url)); var _ = urlTester.GetUrlAsync(Url); } } protected void NotifyPropertyChanged(string memberName) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(memberName)); } } } }