Exemple #1
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            InsertButton.Text = "Running";
            InsertButton.Refresh();

            this.errorHasOccurred = false;
            this.errorDetails     = "";

            if (ConnectionStringTextBox.Text.Length == 0)
            {
                ConnectionStringTextBox.Text = "Server=.;Database=WideWorldImporters;Integrated Security=true;Column Encryption Setting=disabled;Max Pool Size=250;";
            }

            if (!ConnectionStringTextBox.Text.ToUpper().Contains("MAX POOL SIZE"))
            {
                ConnectionStringTextBox.Text = (ConnectionStringTextBox.Text + ";Max Pool Size=250;").Replace(";;", ";");
            }

            var startingTime = DateTime.Now;

            try
            {
                int numberOfThreads = (int)NumberOfThreadsNumericUpDown.Value;

                var sqlTasks = new Thread[numberOfThreads];

                for (int threadCounter = 0; threadCounter < numberOfThreads; threadCounter++)
                {
                    sqlTasks[threadCounter] = new System.Threading.Thread(() => PerformSqlTask(threadCounter, this));
                    sqlTasks[threadCounter].Start();
                }

                if (sqlTasks != null)
                {
                    foreach (Thread thread in sqlTasks)
                    {
                        thread.Join();
                    }
                }
            }
            catch (Exception ex)
            {
                this.errorHasOccurred = true;
                this.errorDetails     = ex.ToString();
            }

            InsertButton.Text             = "&Insert";
            LastExecutionTimeTextBox.Text = ((int)DateTime.Now.Subtract(startingTime).TotalMilliseconds).ToString();

            if (this.errorHasOccurred)
            {
                var errorForm = new ErrorDetailsForm();
                errorForm.ErrorMessage = this.errorDetails;
                errorForm.ShowDialog();
            }
        }
Exemple #2
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            if (InsertButton.Text == "&Insert")
            {
                InsertButton.Text = "&Stop Now";
                InsertButton.Refresh();
                this.Refresh();

                DisplayUpdateTimer.Enabled = true;

                this.errorHasOccurred = false;
                this.errorDetails     = "";

                this.totalOrders       = 0;
                this.totalMilliseconds = 0;

                if (ConnectionStringTextBox.Text.Length == 0)
                {
                    ConnectionStringTextBox.Text = "Server=.;Userid=user;Password=password;Port=5432;Database=wide_world_importers_pg;Pooling=true;MinPoolSize=0;MaxPoolSize=250;SslMode=Require;Trust Server Certificate=true";
                }

                if (!ConnectionStringTextBox.Text.ToUpper().Contains("MAXPOOLSIZE"))
                {
                    ConnectionStringTextBox.Text = (ConnectionStringTextBox.Text + ";MaxPoolSize=250;").Replace(";;", ";");
                }

                try
                {
                    int numberOfThreads = (int)NumberOfThreadsNumericUpDown.Value;

                    sqlTasks = new Thread[numberOfThreads];

                    for (int threadCounter = 0; threadCounter < numberOfThreads; threadCounter++)
                    {
                        PerformSqlTask(threadCounter, this);
                    }
                }
                catch (Exception ex)
                {
                    this.errorHasOccurred = true;
                    this.errorDetails     = ex.ToString();
                }

                if (this.errorHasOccurred)
                {
                    var errorForm = new ErrorDetailsForm();
                    errorForm.ErrorMessage = this.errorDetails;
                    errorForm.ShowDialog();
                }
            }
            else
            {
                InsertButton.Text = "Stopping";
                InsertButton.Refresh();
                this.Refresh();

                DisplayUpdateTimer.Enabled = false;

                if (sqlTasks != null)
                {
                    foreach (Thread thread in sqlTasks)
                    {
                        thread.Abort();
                    }
                }

                InsertButton.Text = "&Insert";
            }
        }