Пример #1
0
        public static DialogResult ShowModal(String title, String message, bool animated,
                                             ReadyDelegate notifyReady, CancelDelegate deleg)
        {
            using (HUDForm instance = new HUDForm())
            {
                // Don't use lock() here as we might dead lock otherwise.
                if (!Monitor.TryEnter(instanceLock))
                {
                    Application.DoEvents(); // See if we can let the application finish pending stuff first.
                    if (!Monitor.TryEnter(instanceLock))
                    {
                        return(DialogResult.Abort); // Still no lock possible? In this case we can only leave without showing the HUD form.
                    }
                }

                currentInstance = instance;
                Monitor.Exit(instanceLock);

                instance.label1.Text    = title;
                instance.label2.Text    = message;
                instance.cancelDelegate = deleg;

                // Can happen the form is cancelled already while we are still doing the setup
                // (separate thread).
                if (instance.IsDisposed || instance.Disposing)
                {
                    if (Monitor.TryEnter(instanceLock))
                    {
                        currentInstance = null;
                        Monitor.Exit(instanceLock);
                    }
                    return(DialogResult.Abort);
                }

                instance.Reshow(animated, true);

                // Need to set Visible back to false to avoid an exception in ShowDialog about an already
                // visible window. Doesn't usually have a visual effect.
                instance.Visible = false;

                if (notifyReady != null)
                {
                    notifyReady();
                }

                DialogResult result = DialogResult.Abort;
                if (!instance.IsDisposed && !instance.Disposing)
                {
                    result = instance.ShowDialog();
                }
                if (Monitor.TryEnter(instanceLock))
                {
                    instance.Dispose();
                    currentInstance = null;
                    Monitor.Exit(instanceLock);
                }

                return(result);
            }
        }
Пример #2
0
 /// <summary>
 /// Hide the HUD and return OK as dialog result.
 /// Always called in the context of the main thread with active lock.
 /// </summary>
 protected void DoFinish()
 {
     if (IsHandleCreated)
     {
         Hide();
     }
     this.DialogResult = DialogResult.Abort;
     Dispose();
     currentInstance = null;
 }
Пример #3
0
        public static void Show(String title, String message, bool animated)
        {
            lock (instanceLock) // Hard lock here. Must never happen.
            {
                HUDForm instance = new HUDForm();
                currentInstance      = instance;
                instance.label1.Text = title;
                instance.label2.Text = message;

                instance.Reshow(animated, false);
            }
        }
Пример #4
0
 /// <summary>
 /// Hide the HUD and return OK as dialog result.
 /// Always called in the context of the main thread with active lock.
 /// </summary>
 protected void DoFinish()
 {
     if (IsHandleCreated)
     Hide();
       this.DialogResult = DialogResult.Abort;
       Dispose();
       currentInstance = null;
 }
Пример #5
0
        public static DialogResult ShowModal(String title, String message, bool animated,
            ReadyDelegate notifyReady, CancelDelegate deleg)
        {
            using (HUDForm instance = new HUDForm())
              {
            // Don't use lock() here as we might dead lock otherwise.
            if (!Monitor.TryEnter(instanceLock))
            {
              Application.DoEvents(); // See if we can let the application finish pending stuff first.
              if (!Monitor.TryEnter(instanceLock))
            return DialogResult.Abort; // Still no lock possible? In this case we can only leave without showing the HUD form.
            }

            currentInstance = instance;
            Monitor.Exit(instanceLock);

            instance.label1.Text = title;
            instance.label2.Text = message;
            instance.cancelDelegate = deleg;

            // Can happen the form is cancelled already while we are still doing the setup
            // (separate thread).
            if (instance.IsDisposed || instance.Disposing)
            {
              if (Monitor.TryEnter(instanceLock))
              {
            currentInstance = null;
            Monitor.Exit(instanceLock);
              }
              return DialogResult.Abort;
            }

            instance.Reshow(animated, true);

            // Need to set Visible back to false to avoid an exception in ShowDialog about an already
            // visible window. Doesn't usually have a visual effect.
            instance.Visible = false;

            if (notifyReady != null)
              notifyReady();

            DialogResult result = DialogResult.Abort;
            if (!instance.IsDisposed && !instance.Disposing)
              result = instance.ShowDialog();
            if (Monitor.TryEnter(instanceLock))
            {
              instance.Dispose();
              currentInstance = null;
              Monitor.Exit(instanceLock);
            }

            return result;
              }
        }
Пример #6
0
        public static void Show(String title, String message, bool animated)
        {
            lock (instanceLock) // Hard lock here. Must never happen.
              {
            HUDForm instance = new HUDForm();
            currentInstance = instance;
            instance.label1.Text = title;
            instance.label2.Text = message;

            instance.Reshow(animated, false);
              }
        }