RadMessageBox - Error when Opening Multiple Instances

12 posts, 0 answers
  1. Travis Parks
    Travis Parks avatar
    7 posts
    Member since:
    Sep 2009

    Posted 28 Dec 2010 Link to this post

    Hello:

    Our users noticed today that RadMessageBox throws an error if additional calls to Show are made while the original dialog is still open. Our application uses BackgroundWorker, so processes alerting the user to their completion is a normal activity. This can result in multiple modal dialogs showing up all at the same time, which is acceptable.

    Until recently, we used the built-in WinForm MessageBox. We switched over to get the common look and feel. However, now we are getting this error: Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.

    We don't want to go back to the ugly MessageBoxes, so it would be nice if there was a way for RadMessageBox to overcome this problem.

    Thanks,
    Travis Parks
  2. Travis Parks
    Travis Parks avatar
    7 posts
    Member since:
    Sep 2009

    Posted 28 Dec 2010 Link to this post

    I also noticed that there is a public constructor in this class, which makes no sense.

    A coworker and I also tried explicitly locking on the type of the RadMessageBox, like so:

    lock (typeof(RadMessageBox))
    {
        RadMessageBox.Show(....);
    }

    However, it would appear that there are some odd things happening with the chosen sync object. If we lock on a separate sync object or on a different type, everything works as expected.

    For now, we are explicitly locking on a different sync object.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Dec 2010 Link to this post

    Hello,

    I haven't been able to replicate your issue. Please can you post a sample showing how to replicate this and I will do my best to see if I can replicate it and post a workaround for you.

    Could you also confirm confirm the version of the RadControls that you are using?
    Many thanks
    Richard
  5. Travis Parks
    Travis Parks avatar
    7 posts
    Member since:
    Sep 2009

    Posted 29 Dec 2010 Link to this post

    Here is a small example demonstrating the problem:

    using System;
    using System.ComponentModel;
    using System.Threading;
    using System.Windows.Forms;
    using Telerik.WinControls;
      
    namespace TestCS
    {
        class Program
        {
            static void Main(string[] args)
            {
                BackgroundWorker worker1 = createBackgroundWorker(1);
                BackgroundWorker worker2 = createBackgroundWorker(5);
                worker1.RunWorkerAsync();
                worker2.RunWorkerAsync();
      
                Application.Run(); // keeps the app alive
            }
      
            private static BackgroundWorker createBackgroundWorker(int seconds)
            {
                BackgroundWorker worker1 = new BackgroundWorker();
                worker1.DoWork += (sender, e) =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(seconds));
                };
                worker1.RunWorkerCompleted += (sender, e) =>
                {
                    RadMessageBox.Show("Completed");
                };
                return worker1;
            }
        }
    }

    Here is a link to the BackgroundWorker documentation that explains why this code should work. http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx You can even see in their examples that the RunWorkCompleted event should be able to interact with the UI.
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 29 Dec 2010 Link to this post

    Hello,

    I can replicate your issue using the RadMessageBox

    System.ArgumentException
      Message=A circular control reference has been made. A control cannot be owned by or parented to itself.
     
    where this doesn't occur with a standard messagebox. At the moment, I cannot offer you a workaround, but if I can find one for you, I'll let you know.
    Regards,
    Richard
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 03 Jan 2011 Link to this post

    Hello Travis Parks,

    Our RadMessageBox is designed in such a way that only one message box could be shown in any moment since our controls are not thread-safe and are intended to work in single-thread scenarios.

    A simple workaround is to create your own message box form with a label and a button and show it using the ShowDialog method. You should use a RadForm in order to achieve the common look and feel.
     
    worker1.RunWorkerCompleted += (sender, e) =>
    {
        MyMessageBox messageBox = new MyMessageBox();
        messageBox.Message = "Completed";
        messageBox.ShowDialog();
    };

    Since your scenario is a common one, we will consider supporting it in a future version. Your Telerik points have been updated.

    Hope this was helpful. If you have any further questions or you need further assistance, feel free write back.

    All the best,
    Ivan Todorov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  8. Mark
    Mark avatar
    32 posts
    Member since:
    Jan 2012

    Posted 28 Aug 2012 Link to this post

    This is also causing me issues in my application and I note that you suggested in the last message that  this is common and you would look into making the control thread safe.

    Is there any update on this?

    Thanks,

    Mark.
  9. Mark
    Mark avatar
    32 posts
    Member since:
    Jan 2012

    Posted 28 Aug 2012 Link to this post

    This is also causing me issues in my application and I note that you suggested in the last message that  this is common and you would look into making the control thread safe.

    Is there any update on this?

    Thanks,

    Mark.
  10. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 30 Aug 2012 Link to this post

    Hello Mark,

    Thank you for writing.

    Could you please share more details on your case so we can investigate it.

    Looking forward to hearing from you.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  11. Jason
    Jason avatar
    24 posts
    Member since:
    Apr 2011

    Posted 28 May 2013 Link to this post

    I upgraded to version 2013.1.321.40 from the previous version in order to get the fix for the RadMessageBox not sizing properly. This new version introduced a bug where when showing the same dialog twice in a row, causes the circular reference exception described earlier. I'm not doing any background threading or anything. I'm basically just showing a dialog from a button click event handler, then clicking ok to close the dialog, then clicking the button to show it again. On the second time I'll get:
    A circular control reference has been made. A control cannot be owned by or parented to itself.
    This only happens in certain places in my app, and I'm trying to figure out why it occurs on some dialogs but not others. I've also noticed that changing the call from :
    RadMessageBox.Show("My Text");
    to
    RadMessageBox.Show(this, "My Text");
    resolves the issue...though I'm not sure why. I've also verified that the error doesn't occur in the previous version of the controls.

    Thanks,
    Jason
  12. Anton
    Admin
    Anton avatar
    167 posts

    Posted 31 May 2013 Link to this post

    Hi Jason,

    Thank you for writing.

    In Q1 2013 we changed core functionality in
    RadMessageBox. Before the change, RadMessageBox was disposing after each usage, now the instance is not disposed and it is reused to show all messages (singleton). This change in the behavior of the control lead to several issues and most of them we already resolved. 

    We were aware about this issue and we already have a related pits item
    http://www.telerik.com/support/pits.aspx#/public/winforms/14649. This issue appears when your Form hasits TopMost property set to true and RadMessageBox does not have owner. To workaround this issue you have several ways:

    1. Set TopMost property of your form to false.
    2. Set the owner of the RadMessageBox (as you already found out).
    3. Dispose the instance of RadMessageBox after every usage.

    RadMessageBox.Show("Text");
    RadMessageBox.Instance.Dispose();

    I hope this helps and please excuse us for the introduced inconvenience.

    Regards,
    Anton
    Telerik
    RadChart for WinForms is obsolete. Now what?
  13. Jason
    Jason avatar
    24 posts
    Member since:
    Apr 2011

    Posted 31 May 2013 Link to this post

    Thanks for the info Anton. I appreciate it!
Back to Top
UI for WinForms is Visual Studio 2017 Ready