public static void Stop() { if (webserver != null) { try { webserver.Stop(); } catch (Exception e) { _logger.InfoFormat("Stop MyHttpServer:{0}", e); } } }
private void TimerForm_FormClosing(object sender, FormClosingEventArgs formClosingEvent) { if (MessageBox.Show(Resources.TimerForm_TimerForm_FormClosing_Are_you_sure_you_want_to_close_this_window_, Resources.TimerForm_TimerForm_FormClosing_Are_you_sure_, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { formClosingEvent.Cancel = true; return; } _simpleHttpServer.Stop(); #if !DEBUG try { Directory.Delete(_timerPath, true); } catch { // ignore } #endif }
private void Main_FormClosing(object sender, FormClosingEventArgs e) { _simpleHttpServer.Stop(); Browser.Dispose(); Cef.Shutdown(); }
private void CreateDirectoryAndUnZip(bool askForPath = false) { var t = Task.Run(async() => { if (askForPath) { using var openFolderDialog = new FolderBrowserDialog(); while (openFolderDialog.ShowDialog() != DialogResult.OK) { MessageBox.Show(Resources.TimerForm_CreateDirectoryAndUnZip_Please_choose_valid_location, Resources.TimerForm_CreateDirectoryAndUnZip_You_have_to_choose_location, MessageBoxButtons.OK, MessageBoxIcon.Information); } _timerPath = openFolderDialog.SelectedPath; } try { await TryMultipleTimes(() => { if (!Directory.Exists(_timerPath)) { Directory.CreateDirectory(_timerPath); } }); } catch (Exception e) { MessageBox.Show( string.Format( Resources .TimerForm_CreateDirectoryAndUnZip_Couldn_t_create_directory__0__because__1___please_choose_another_location, _timerPath, e.Message), Resources.TimerForm_WriteTournamentTimer_Something_went_wrong, MessageBoxButtons.OK, MessageBoxIcon.Error); CreateDirectoryAndUnZip(true); } #if !DEBUG try { await TryMultipleTimes(() => { ZipFile.ExtractToDirectory(Application.StartupPath + "\\WebApp.app", _timerPath); }); } catch (Exception e) { MessageBox.Show( string.Format(Resources.TimerForm_CreateDirectoryAndUnZip_Couldn_t_extract_web_app_files_to_directory__0__because__1___please_choose_another_location, _timerPath, e.Message), Resources.TimerForm_WriteTournamentTimer_Something_went_wrong, MessageBoxButtons.OK, MessageBoxIcon.Error); CreateDirectoryAndUnZip(true); } #endif _simpleHttpServer?.Stop(); _simpleHttpServer = new SimpleHttpServer(_timerPath); }); t.Wait(); }