private void BtnStart_Click(object sender, RoutedEventArgs e) { StartTimer(); BtnStart.IsEnabled = false; BtnStop.IsEnabled = true; LoggerManager.AddLogMessage("Server", "Starting..."); { try { //var saveString = File.ReadAllText(_filePath); //TODO world load //World.Circles = JsonConvert.DeserializeObject<List<Circle>>(saveString); } catch (Exception ex) { if (ex is DirectoryNotFoundException) { MaterialMessageBox.Show("Invalid directory\nException: " + ex.Message); } else if (ex is FileNotFoundException) { MaterialMessageBox.Show("Invalid file name\nException: " + ex.Message); } else if (ex is ArgumentNullException) { MaterialMessageBox.Show("You must select a map file first\nException: " + ex.Message); } else { MaterialMessageBox.Show("Error.\nException: " + ex.Message); } LoggerManager.ServerMsg("Could not load map file, Shutting down..."); BtnStart.IsEnabled = true; BtnStop.IsEnabled = false; return; //TODO return } LoggerManager.ServerMsg("Successfully imported map."); } _cancellationTokenSource = new CancellationTokenSource(); _task = new Task(_server.Run, _cancellationTokenSource.Token); _task.Start(); }