private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { TcpServer.StopServer(); if (_uiHandler != null) { _uiHandler.Dispose(); } } catch (Exception exception) { MessageBox.Show($"FormClosing() throws an exception: {exception.Message}"); } }