From 08f6288f9197e9c9edf5345759a2823556b0df8f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 22 Mar 2024 00:56:40 +0100 Subject: [PATCH] Run URL check using a task --- Tasks/UrlTester/MainWindow.xaml.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Tasks/UrlTester/MainWindow.xaml.cs b/Tasks/UrlTester/MainWindow.xaml.cs index c412bbb..996f0e6 100644 --- a/Tasks/UrlTester/MainWindow.xaml.cs +++ b/Tasks/UrlTester/MainWindow.xaml.cs @@ -25,11 +25,22 @@ public partial class MainWindow : Window public void GetUrl(object sender, RoutedEventArgs e) { + var tester = new DT2.UrlTester(); var stopWatch = new Stopwatch(); - stopWatch.Start(); - int size = new DT2.UrlTester().GetUrlSync(urlBox.Text); - stopWatch.Stop(); - bytesBox.Text = $"{size} bytes"; - timeBox.Text = $"{stopWatch.ElapsedMilliseconds} ms"; + + tester.PageStart += (_) => + { + stopWatch.Start(); + }; + + tester.PageLoaded += (_, size) => + { + stopWatch.Stop(); + bytesBox.Text = $"{size} bytes"; + timeBox.Text = $"{stopWatch.ElapsedMilliseconds} ms"; + timeBar.Value = stopWatch.ElapsedMilliseconds; + }; + + _ = tester.GetUrlAsync(urlBox.Text); } } \ No newline at end of file