BF2Statistics.LoadingForm.CloseForm C# (CSharp) Method

CloseForm() public static method

Method called to close the update form
public static CloseForm ( ) : void
return void
        public static void CloseForm()
        {
            // No exception here
            if (Instance == null || Instance.IsDisposed)
                return;

            try
            {
                Instance.Invoke((Action)delegate
                {
                    Instance.Close();
                    Instance = null;
                });
            }
            catch { }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Event fired when the Test button is clicked
        /// </summary>
        private async void TestBtn_Click(object sender, EventArgs e)
        {
            // Build Connection String
            MySqlConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();

            Builder.Server   = Hostname.Text;
            Builder.Port     = (uint)Port.Value;
            Builder.UserID   = Username.Text;
            Builder.Password = Password.Text;
            Builder.Database = DBName.Text;

            // Attempt to connect, reporting any and all errors
            try
            {
                // Show loading form
                LoadingForm.ShowScreen(this, true, "Connecting to MySQL Database...");
                SetNativeEnabled(false);

                // Dont lock up the program
                await Task.Run(() =>
                {
                    using (MySqlConnection Connection = new MySqlConnection(Builder.ConnectionString))
                    {
                        Connection.Open();
                        Connection.Close();
                    }
                });
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message, "Connection Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1,
                                (MessageBoxOptions)0x40000 // Force window on top
                                );
                return;
            }
            finally
            {
                LoadingForm.CloseForm();
                SetNativeEnabled(true);
            }

            // Show success after loading form has been called to close
            MessageBox.Show("Connection Successful!", "Success", MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                            (MessageBoxOptions)0x40000 // Force window on top
                            );
        }
All Usage Examples Of BF2Statistics.LoadingForm::CloseForm