BF2Statistics.MainForm.StartAspServerBtn_Click C# (CSharp) Method

StartAspServerBtn_Click() private method

Starts and stops the ASP HTTP server
private StartAspServerBtn_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private async void StartAspServerBtn_Click(object sender, EventArgs e)
        {
            if (!HttpServer.IsRunning)
            {
                // Display loading image and disable buttons
                AspStatusPic.Image = Resources.loading;
                AspStatusLabel.Text = "Starting...";
                AspStatusLabel.ForeColor = Color.Orange;
                ToggleAspServerBtn.Enabled = false;
                ToggleWebServerBtn.Enabled = false;
                ToggleGamespyEmuBtn.Enabled = false;
                ToggleGamespyServerBtn.Enabled = false;

                // Start Server
                try
                {
                    // Start Server in a different thread, Dont want MySQL locking up the GUI
                    await Task.Run(() => HttpServer.Start());
                }
                catch (HttpListenerException E)
                {
                    // Custom port 80 in use message
                    string Message = (E.ErrorCode == 32) ? "Port 80 is already in use by another program." : E.Message;

                    // Warn the user of the exception
                    AspStatusPic.Image = Resources.warning;
                    Tipsy.SetToolTip(AspStatusPic, Message);
                    Notify.Show("Failed to start ASP Server!", Message, AlertType.Warning);
                }
                catch (Exception E)
                {
                    // Check for specific error
                    Program.ErrorLog.Write("[ASP Server] " + E.Message);
                    AspStatusPic.Image = Resources.warning;
                    Tipsy.SetToolTip(AspStatusPic, E.Message);

                    // Show the DB exception form if its a DB connection error
                    if (E is DbConnectException)
                        ExceptionForm.ShowDbConnectError(E as DbConnectException);
                    else
                        Notify.Show("Failed to start ASP Server!", E.Message, AlertType.Warning);
                }
                finally
                {
                    // Enable buttons again
                    ToggleAspServerBtn.Enabled = true;
                    ToggleWebServerBtn.Enabled = true;
                    ToggleGamespyEmuBtn.Enabled = true;
                    ToggleGamespyServerBtn.Enabled = true;

                    // Set texts
                    if (!HttpServer.IsRunning)
                    {
                        AspStatusLabel.Text = "Stopped";
                        AspStatusLabel.ForeColor = SystemColors.ControlDark;
                    }
                }
            }
            else
            {
                try
                {
                    HttpServer.Stop();
                    Tipsy.SetToolTip(AspStatusPic, "Asp server is currently offline");
                }
                catch (Exception E)
                {
                    Program.ErrorLog.Write(E.Message);
                }
            }
        }
MainForm