private void Positioning() { try { /* Load fingerprinting data from the server */ List <AdjustedFingerprinting> fingerprintings = IndoorPositioningClient.GetFingerprintings(environment.EnvironmentId); /* Disappear the loading splash screen */ Application.Current.Dispatcher.Invoke(() => ShowLoadingScreen = false); while (PositioningActivated) { try { Coordinate coordinate = new Coordinate(); /* Run KNNClassifier */ if (SelectedAlgorithmIndex == 0) { coordinate = Positioning_Knn(fingerprintings); } else if (SelectedAlgorithmIndex == 1) { coordinate = Positioning_KnnProximity(fingerprintings); } else if (SelectedAlgorithmIndex == 2) { coordinate = Positioning_Proximity(); } else { throw new Exception("Invalid algorithm"); } /* Success process, clear error message if any */ Application.Current.Dispatcher.Invoke(() => txtAlert.Text = ""); /* Add the beacon localized onto the screen */ Application.Current.Dispatcher.Invoke(() => environmentShape.MoveBeacon(coordinate.Xaxis, coordinate.Yaxis)); } catch (ThreadAbortException) { break; } catch (Exception ex) { Application.Current.Dispatcher.Invoke(() => txtAlert.Text = ex.Message); } finally { /* Every second, query the server for the RSSI values read by the gateways */ Thread.Sleep(2000); } } } catch (ThreadAbortException) { /* do nothing */ } catch (Exception ex) { Application.Current.Dispatcher.Invoke(() => MessageBox.Show(ex.ToString())); } }