/// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>The new certificate.</returns>
        public bool ShowDialog(IWin32Window owner, TrustCertificateDialogSettings settings, int timeout)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            m_settings = settings;

            if (timeout != 0)
            {
                m_counter            = timeout / 1000 + 1;
                TimeoutTimer.Enabled = true;
            }

            CountdownLabel.Visible = (timeout != 0);
            WarningLabel.Visible   = false;

            if (settings.ValidationError.IsBad())
            {
                WarningLabel.Text = "This certificate is not trusted ({0}).\r\nPlease review and decide if you would like to trust it.";
                WarningLabel.Text = String.Format(WarningLabel.Text, settings.ValidationError);
            }

            WarningLabel.Visible = settings.ValidationError.IsBad();

            if (settings.IsHttpsCertificate)
            {
                PermanentCheckBox.Visible     = false;
                ApplicationNameLabel.Text     = "Domain Name";
                ApplicationUriLabel.Visible   = false;
                ApplicationUriTextBox.Visible = false;
                DomainNamesLabel.Visible      = false;
                DomainNamesTextBox.Visible    = false;
            }

            ICertificate certificate = settings.UntrustedCertificate;

            if (certificate != null)
            {
                Update(certificate);
            }

            if (base.ShowDialog(owner) != DialogResult.OK)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>True if the certificate should be trusted.</returns>
        public static bool ShowDialog(Form owner, TrustCertificateDialogSettings settings, int timeout)
        {
            if (owner != null && owner.InvokeRequired)
            {
                ManualResetEvent e = new ManualResetEvent(false);

                bool?result = owner.Invoke(new ShowDialogEventHandler(ShowDialog), owner, settings, timeout, e) as bool?;

                if (!e.WaitOne(timeout + 200))
                {
                    return(false);
                }

                return((result != null) ? result.Value : false);
            }

            return(ShowDialog(null, settings, timeout, null));
        }
        private static bool ShowDialog(IWin32Window owner, TrustCertificateDialogSettings settings, int timeout, ManualResetEvent e)
        {
            TrustCertificateDialog dialog = new TrustCertificateDialog();

            dialog.StartPosition = FormStartPosition.CenterParent;

            bool result = dialog.ShowDialog(owner, settings, timeout);

            if (e != null)
            {
                e.Set();

                if (!dialog.IsDisposed)
                {
                    dialog.Close();
                }
            }

            return(result);
        }