15 Answers, 1 is accepted
can you share how you did this? I am looking for the same thing here. My scenario is when my form loads, i spawn a background worker that checks a database table once every 5 minutes in a loop. I want to open a desktop alert if a particular value is returned in the sql query. I would like to then update the content with what was returned from the query and show the alert.
thanks!
Jonathan
Thank you for your question.
I am posting below a sample code that shows how to use a background worker to spawn desktop alerts. The key part is using a MethodInvoker to protect your code from cross-thread operations and show the alerts in the UI thread rather than the background one:
private
void
Form1_Load(
object
sender, EventArgs e)
{
BackgroundWorker bw =
new
BackgroundWorker();
bw.DoWork +=
new
DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
}
private
void
CreateAndShowAlert(
string
caption,
string
text)
{
RadDesktopAlert desktopAlert =
new
Telerik.WinControls.UI.RadDesktopAlert(
);
desktopAlert.CaptionText = caption;
desktopAlert.ContentText = text;
desktopAlert.Show();
}
void
bw_DoWork(
object
sender, DoWorkEventArgs e)
{
int
i = 0;
while
(
true
)
{
Thread.Sleep(3000);
i++;
MethodInvoker mi =
new
MethodInvoker(
delegate
() {
this
.CreateAndShowAlert(
"Alert "
+ i,
"This is the "
+ i +
"th alert"
); });
this
.Invoke(mi);
}
}
Hope this answers your question. If you need further help, do not hesitate to contact me.
Regards,
Ivan Todorov
the Telerik team
This seems like a suitable replacement for MessageBox.Show(). MessageBox doesn't need to be on the UI thread.
If I try to show an alert from outside the UI thread I get a black alert that I can not close and is unresponsive.
If you cannot access the UI thread, you can create a new one by the Application.Run() method. Below is a sample of this.
The following form hides itself and only displays a RadDesktopAlert. The form is closed when the alert is closed:
public
partial
class
AlertForm : Form
{
public
AlertForm()
{
InitializeComponent();
RadDesktopAlert alert =
new
RadDesktopAlert();
alert.Closed +=
new
RadPopupClosedEventHandler(alert_Closed);
alert.Show();
}
void
alert_Closed(
object
sender, RadPopupClosedEventArgs args)
{
this
.Close();
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
this
.Hide();
this
.ShowInTaskbar =
false
;
}
}
The following form runs the previous one in a separate thread. The result is that a RadDesktopAlert is shown without having access to the main form.
public
partial
class
MainForm: Form
{
public
MainForm()
{
InitializeComponent();
BackgroundWorker bw =
new
BackgroundWorker();
bw.DoWork +=
new
DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
}
void
bw_DoWork(
object
sender, DoWorkEventArgs e)
{
Application.Run(
new
Form26());
}
}
I hope this is useful. Should you have any additional questions, do not hesitate to ask.
All the best,
Ivan Todorov
the Telerik team
I like your idea though. I never thought about doing that.
This info was VERY useful. Thank you. I was expecting this control to work like MessageBox and have been searching both for a reason it doesn't and a solution. Still don't know the reason but at least now I know the solution. Solutions like this should be part of the Telerik documentation, or at least the documentation should note that this control can't be (easily) shown from a thread that's not the main UI thread.
Thanks again,
Steve
Thank you for writing.
The RadMessageBox is essentially showing a RadForm which is a Form. When a Form is shown from a thread with no message pump, it starts its own, temporary message pump. However, RadDesktopAlert is a component which does not have such functionality, that is where the difference is.
It is a good practice and is in most cases mandatory to access/create/show controls or forms only from the UI thread, that is why we have not considered adding such documentation articles. We have, however a KB article which is concerning RadGridView, however the practices applied in that article can be used with other components. You can find the article here. You can also read the articles at the bottom.
Let me know if you have further questions.
Regards,
George
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Hi everyone!
We have a problem with the RadDesktopAlert we are using in our Application (we are using radForm).
We have a button in our app, in which we have some specific code to achive some tasks when the user press it, so we want that when users press the button a RadDesktopAlert will be shown in their screen to inform them that the Tool is creating the files and once the files are created, the RadDesktopAlert must be closed.
Our problem is that if I add this.radDesktopAlert1.Show(); in the beggining of the button method, the radDesktopAlert1 is shown in my screen but if it is inside of an if-else it is not shown and I have no idea why it is.
I have added an attachment which shows a part of the code where I have to use the radDesktopAlert1 and it is not working, so please can you be so kind and help me with this? I don't really understand why the radDesktopAlert1 it is working when it is in the begining of the button method and why it is NOT working just a few lines below.
THANKS A LOT IN ADVANCE!
Thank you for writing.
Can you please check if your if-else clause has been hit and you are able to break there? If you are actually able to break and the desktop alert still does not show I am going to need a sample project to be investigated locally. In order to send us your project, you will need to use the ticketing straight from your Telerik Account.
I hope this helps. Please let me know if you have other questions.
Regards,
Hristo
Progress Telerik
Hi,
Yes, I am able to break inside the if/else clause, but the problem is that I have a dialogreult where the User has to press yes or not. In case they press yes, the raddesktopalert should be shown in the screen, but it is not like that. The thing is that if I put the raddesktopalert.show() after de dialogresult.Yes it is not shown. If I put it above the dialogresult it is shown. I don't understand why.
Any ideas why?
Thanks a lot in advance!
Thank you for writing back.
I am not able to reproduce this in a simple scenario. Can you please check the attached project? In case you keep experiencing the issue please open a support ticket and send us a project reproducing the behavior on your end.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo
Progress Telerik
This thread discusses the how the desktop alert can be accessed from a separate thread. Can you please elaborate on your question and provide more details about your actual scenario. In case it is not related to the discussed topic, you can open a separate thread.
Thank you for understanding.
Regards,
Hristo
Progress Telerik