From 2cb3fd5ec303e9e8a634d4101a98b549b864c40c Mon Sep 17 00:00:00 2001 From: shinichi Date: Fri, 9 Oct 2020 11:33:26 +0200 Subject: [PATCH] ble and simulation stop when window closes --- ClientApp/Views/MainWindow.xaml.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ClientApp/Views/MainWindow.xaml.cs b/ClientApp/Views/MainWindow.xaml.cs index d718f1e..c86bbde 100644 --- a/ClientApp/Views/MainWindow.xaml.cs +++ b/ClientApp/Views/MainWindow.xaml.cs @@ -16,6 +16,7 @@ using System.Windows.Shapes; using ClientApp.Utils; using Hardware.Simulators; using System.Threading; +using ProftaakRH; namespace ClientApp { @@ -24,31 +25,33 @@ namespace ClientApp /// public partial class MainWindow : Window { + private IHandler handler; public MainWindow() { Client client = new Client(); - InitializeComponent(); DataContext = new MainWindowViewModel(client); - //BLEHandler bLEHandler = new BLEHandler(client); //bLEHandler.Connect(); //client.setHandler(bLEHandler); - BikeSimulator bikeSimulator = new BikeSimulator(client); Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation)); newThread.Start(); - client.SetHandler(bikeSimulator); + handler = bikeSimulator; + } - + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + handler.stop(); } } }