public ContainerForm(ServiceBusHelper serviceBusHelper, MainForm mainForm, FormTypeEnum formType, QueueDescription queueDescription)
        {
            try
            {
                InitializeComponent();
                Task.Factory.StartNew(AsyncWriteToLog).ContinueWith(t =>
                {
                    if (t.IsFaulted && t.Exception != null)
                    {
                        WriteToLog(t.Exception.Message);
                    }
                });
                this.mainForm = mainForm;
                mainSplitterDistance = mainSplitContainer.SplitterDistance;
                SuspendLayout();
                panelMain.SuspendDrawing();
                panelMain.Controls.Clear();
                panelMain.BackColor = SystemColors.GradientInactiveCaption;

                if (formType == FormTypeEnum.Listener)
                {
                    var listenerControl = new ListenerControl(WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), queueDescription)
                    {
                        Location = new Point(1, panelMain.HeaderHeight + 1),
                        Size = new Size(panelMain.Size.Width - 3, queueDescription.RequiresSession ? 544 : 520),
                        Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };
                    listenerControl.Focus();

                    Text = string.Format(QueueListenerFormat, queueDescription.Path);
                    mainSplitContainer.SplitterDistance = queueDescription.RequiresSession ? 570 : listenerControl.Size.Height + 26;
                    panelMain.HeaderText = string.Format(HeaderTextQueueListenerFormat, queueDescription.Path);
                    panelMain.Controls.Add(listenerControl);
                }
                else
                {
                    testQueueControl = new TestQueueControl(mainForm, WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), queueDescription)
                                           {
                                               Location = new Point(1, panelMain.HeaderHeight + 1),
                                               Size = new Size(panelMain.Size.Width - 3, panelMain.Size.Height - 26),
                                               Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                                           };


                    if (formType == FormTypeEnum.Send)
                    {
                        testQueueControl.mainTabControl.TabPages.RemoveAt(2);
                        testQueueControl.receiverEnabledCheckBox.Checked = false;
                        testQueueControl.senderEnabledCheckBox.Checked = true;
                        testQueueControl.senderEnabledCheckBox.Visible = false;
                        testQueueControl.grouperMessage.Location = new Point(testQueueControl.grouperMessage.Location.X, 8);
                        testQueueControl.grouperMessage.Size = new Size(testQueueControl.grouperMessage.Size.Width, 
                                                                        testQueueControl.grouperMessage.Size.Height + 16);
                        testQueueControl.grouperSender.Location = new Point(testQueueControl.grouperSender.Location.X, 8);
                        testQueueControl.grouperSender.Size = new Size(testQueueControl.grouperSender.Size.Width,
                                                                       testQueueControl.grouperSender.Size.Height + 16);
                        Text = string.Format(SendMessagesFormat, queueDescription.Path);
                    }
                    else
                    {
                        Text = string.Format(TestQueueFormat, queueDescription.Path);
                        logTraceListener = new LogTraceListener(WriteToLog);
                        Trace.Listeners.Add(logTraceListener);
                    }

                    testQueueControl.btnCancel.Text = CloseLabel;
                    testQueueControl.btnCancel.Click -= testQueueControl.btnCancel_Click;
                    testQueueControl.btnCancel.Click += BtnCancelOnClick;
                    testQueueControl.Focus();

                    panelMain.HeaderText = string.Format(HeaderTextTestQueueFormat, queueDescription.Path);
                    panelMain.Controls.Add(testQueueControl);
                }
                SetStyle(ControlStyles.ResizeRedraw, true);
            }
            finally
            {
                panelMain.ResumeDrawing();
                ResumeLayout();
            }
        }
        private void TestQueue(QueueDescription queueDescription, bool sdi)
        {
            if (sdi)
            {
                TestQueueControl queueControl = null;

                try
                {
                    panelMain.SuspendDrawing();
                    foreach (var userControl in panelMain.Controls.OfType<UserControl>())
                    {
                        userControl.Dispose();
                    }
                    panelMain.Controls.Clear();
                    panelMain.BackColor = SystemColors.GradientInactiveCaption;
                    queueControl = new TestQueueControl(this,
                                                        WriteToLog,
                                                        StopLog,
                                                        StartLog,
                                                        serviceBusHelper,
                                                        queueDescription);
                    queueControl.SuspendDrawing();
                    queueControl.Location = new Point(1, panelLog.HeaderHeight + 1);
                    panelMain.Controls.Add(queueControl);
                    SetControlSize(queueControl);
                    queueControl.OnCancel += MainForm_OnCancel;
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
                finally
                {
                    panelMain.ResumeDrawing();
                    if (queueControl != null)
                    {
                        queueControl.ResumeDrawing();
                    }
                }
            }
            else
            {
                var form = new ContainerForm(serviceBusHelper, this, FormTypeEnum.Test, queueDescription);
                form.Show();
            }
        }