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
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.
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
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.
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
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,
Is there any update on this?
Thanks,
Mark.
Is there any update on this?
Thanks,
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
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
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
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
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.