Arma2NETMySQLPlugin.MySQL.OpenConnection C# (CSharp) Method

OpenConnection() public method

public OpenConnection ( string connectionString ) : void
connectionString string
return void
        public override void OpenConnection(string connectionString)
        {
            // if there is no connection
            if (connection == null)
            {
                connection = new MySqlConnection(connectionString);
            }
            // if there is a connection and it is a different connection string
            else if (connection.ConnectionString != connectionString)
            {
                // close old connection and create with the new connection string
                CloseConnection();
                connection = new MySqlConnection(connectionString);
            }

            //save the connection string, we'll need this if the check thread ever closes down the connection
            connectString = connectionString;

            //update the last time a query has been run
            lastQuery = DateTime.Now;

            //start up thread that checks to see how long we've gone since running a command
            //we run into problems if the MySQL connection is kept open for significantly long periods of time
            if (staleConnectionThread == null) {
                staleConnectionThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(checkConnectionThread));
                staleConnectionThread.Name = "staleConnectionThread";
                staleConnectionThread.Start();
            } else if (staleConnectionThread.ThreadState != System.Threading.ThreadState.Running) {
                staleConnectionThread.Start();
            }

            while (connection.State != System.Data.ConnectionState.Open)
            {
                try
                {
                    //Logger.addMessage(Logger.LogType.Info, "Opening MySQL connection.");
                    connection.Open();
                }
                catch (Exception ex)
                {
                    Logger.addMessage(Logger.LogType.Info, "Unable to open connection to MySQL database, trying again in 10 seconds." + ex.ToString());
                    Thread.Sleep(10000);
                }
            }
        }