diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-10-26 18:31:10 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-10-26 18:31:10 -0700 |
commit | 81cb4bc8d60bba7040d1bee24a44ae05566f5f25 (patch) | |
tree | adddf9b9ee421504cf0d9466d53cd0c7a40c069b /windows | |
parent | 352b83252fb2617a15cde0927cc30110b729e46d (diff) | |
download | infinitytier-81cb4bc8d60bba7040d1bee24a44ae05566f5f25.tar.gz infinitytier-81cb4bc8d60bba7040d1bee24a44ae05566f5f25.zip |
set up a timer to update the UI from a background thread
Diffstat (limited to 'windows')
-rw-r--r-- | windows/WinUI/MainWindow.xaml.cs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index afe6947c..4e7638b6 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Timers; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -13,6 +14,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Windows.Threading; namespace WinUI { @@ -25,6 +27,8 @@ namespace WinUI Regex charRegex = new Regex("[0-9a-fxA-FX]"); Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); + Timer timer = new Timer(); + public MainWindow() { InitializeComponent(); @@ -33,22 +37,50 @@ namespace WinUI updateNetworks(); DataObject.AddPastingHandler(joinNetworkID, OnPaste); + + timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); + timer.Interval = 2000; + timer.Enabled = true; } private void updateStatus() { var status = handler.GetStatus(); - this.networkId.Content = status.Address; - this.versionString.Content = status.Version; - this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE"); + networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.networkId.Content = status.Address; + })); + versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.versionString.Content = status.Version; + })); + onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE"); + })); } private void updateNetworks() { var networks = handler.GetNetworks(); - networksPage.setNetworks(networks); + networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + networksPage.setNetworks(networks); + })); + } + + private void updatePeers() + { + + } + + private void OnUpdateTimer(object source, ElapsedEventArgs e) + { + updateStatus(); + updateNetworks(); + updatePeers(); } private void joinButton_Click(object sender, RoutedEventArgs e) |