This is a migrated thread and some comments may be shown as answers.

RadMessageBox - Error when Opening Multiple Instances

13 Answers 135 Views
MessageBox
This is a migrated thread and some comments may be shown as answers.
Travis Parks
Top achievements
Rank 1
Travis Parks asked on 28 Dec 2010, 07:34 PM
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

13 Answers, 1 is accepted

Sort by
0
Travis Parks
Top achievements
Rank 1
answered on 28 Dec 2010, 10:30 PM
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.
0
Richard Slade
Top achievements
Rank 2
answered on 28 Dec 2010, 11:14 PM
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
0
Travis Parks
Top achievements
Rank 1
answered on 29 Dec 2010, 09:04 PM
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.
0
Richard Slade
Top achievements
Rank 2
answered on 29 Dec 2010, 10:13 PM
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
0
Ivan Todorov
Telerik team
answered on 03 Jan 2011, 04:56 PM
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.
0
Mark
Top achievements
Rank 1
answered on 28 Aug 2012, 09:58 AM
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.
0
Mark
Top achievements
Rank 1
answered on 28 Aug 2012, 09:58 AM
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.
0
Ivan Todorov
Telerik team
answered on 30 Aug 2012, 12:10 PM
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 >>
0
Jason
Top achievements
Rank 1
answered on 28 May 2013, 10:31 PM
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
0
Anton
Telerik team
answered on 31 May 2013, 03:41 PM
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?
0
Jason
Top achievements
Rank 1
answered on 31 May 2013, 04:01 PM
Thanks for the info Anton. I appreciate it!
0
Albert
Top achievements
Rank 1
answered on 12 Apr 2021, 05:05 PM

Hi guys

 

We have the same issue as Travis explained exactly in his post.

We are working with a BackgroundWorker and this one sometimes shows a RadMessageBox.

The problem is that the RadMessageBox is not showed as modal and sometimes is not showed in front.

Do you know how to fix it?, we cannot use the parameter this (the winform) when we are calling the RadMessageBox because is created by another process, not by the BackgroundWorker.

Thanks and regards,

Albert

 

 

      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");    ------>  as commented if we try    with RadMessageBox.Show(this, "Completed");  the application fails because 'this' is not understood by the BackgroundWorker 
            };
            return

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Apr 2021, 09:31 AM

Hello, Albert, 

Following the provided information, I have prepared a sample project to test the behavior on my end with the latest version (2021.1.223) of the Telerik UI for WinForms suite. Please refer to the attached gif file illustrating the behavior on my end with the specified version. I have attached my sample project. Am I missing something? Could you please specify the exact steps how to reproduce the problem?

Alternatively, you can submit a support ticket from your Telerik account and provide a sample runnable project demonstrating the problem you are facing. Thus, we would be able to reproduce the experienced issue and investigate the precise case. Thank you in advance. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
MessageBox
Asked by
Travis Parks
Top achievements
Rank 1
Answers by
Travis Parks
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Ivan Todorov
Telerik team
Mark
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Anton
Telerik team
Albert
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or