private async Task <FrmBaseForm> CreateNewForm <T>(Type formType, string key, CancellationTokenSource cts)
            where T : FrmBaseForm
        {
            T      newForm = null;
            Splash splash  = null;

            FormWrapper removedImmediateFormWrapper;

            try
            {
                newForm = CreateNewForm <T>(formType, key);
                splash  = SplashManager.ShowEmbeddedSplash(newForm);
                CancelEventHandler newFormOnClosing = null;
                newForm.Closing += newFormOnClosing = (s, e) =>
                {
                    ImmediateFormWrappers.TryRemove(key, out removedImmediateFormWrapper);

                    WinformExtensions.ExecuteActionSwallowExceptions(cts.Cancel);
                    WinformExtensions.ExecuteActionSwallowExceptions(cts.Dispose);
                    splash?.Dispose();
                    newForm.Closing -= newFormOnClosing;
                };

                newForm.OnUiThread(() => newForm.Show(_dockPanel, DockState.Document));

                await newForm.InitAsync(cts.Token);

                //if (cache != _formsCache)
                //{
                //    throw new Exception("The form was opened for another customer (but wasn't initialized until now). Kill it!");
                //}

                splash?.Dispose();
            }
            catch (TaskCanceledException)
            {
                ImmediateFormWrappers.TryRemove(key, out removedImmediateFormWrapper);
                WinformExtensions.ExecuteActionSwallowExceptions(newForm.Close);
                splash?.Dispose();
                throw;
            }
            catch (Exception)
            {
                ImmediateFormWrappers.TryRemove(key, out removedImmediateFormWrapper);
                WinformExtensions.ExecuteActionSwallowExceptions(cts.Cancel);
                WinformExtensions.ExecuteActionSwallowExceptions(cts.Dispose);
                if (newForm != null)
                {
                    WinformExtensions.ExecuteActionSwallowExceptions(newForm.Close);
                }
                splash?.Dispose();
                throw;
            }

            return(newForm);
        }
Esempio n. 2
0
        private static DialogResult DoError(string msg, Exception ex, bool showCancel, string ingress)
        {
            if (ex == null)
            {
                ex = new Exception("Unknown exception");
            }

            var box = new FrmExceptionDialogue(new WindowsClipboard())
            {
                Ingress          = ingress ?? "Exception occured",
                ErrorDetails     = ex.ToString(),
                ErrorMsg         = msg,
                ShowCancelButton = showCancel
            };
            var owner = GetOwner();

            return(WinformExtensions.OnUiThread(owner, ctl => box.ShowDialog(ctl)));

            //MessageBox.Show(_owner, msg, SetRightTitle(null), MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Esempio n. 3
0
        public static DialogResult Show(string msg, string title, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            var owner = GetOwner();

            return(WinformExtensions.OnUiThread(owner, ctl => MessageBox.Show(ctl, msg, SetRightTitle(title), buttons, icon)));
        }
Esempio n. 4
0
        public static void Show(string msg, string title = null)
        {
            var owner = GetOwner();

            WinformExtensions.OnUiThread(owner, ctl => MessageBox.Show(ctl, msg, title));
        }