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

Access from another thread.

15 Answers 217 Views
DesktopAlert
This is a migrated thread and some comments may be shown as answers.
pmoney pmoney
Top achievements
Rank 1
pmoney pmoney asked on 21 Dec 2010, 06:46 PM
How can I access radDesktopAlert1.show from another thread?

15 Answers, 1 is accepted

Sort by
0
pmoney pmoney
Top achievements
Rank 1
answered on 21 Dec 2010, 07:21 PM
Never mind I got it working correctly. :)
0
Jonathan Hylton
Top achievements
Rank 1
answered on 09 Feb 2011, 07:01 PM
Hi Pmoney,

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
0
Brian
Top achievements
Rank 1
answered on 11 Feb 2011, 04:04 PM
I have had issues with popping an alert from a sepearate thread from the main gui thread. The way that I got around this was by alerting the main thread (with a delegate) to pop the alert and with what information.
0
Ivan Todorov
Telerik team
answered on 11 Feb 2011, 05:13 PM
Hello 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
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 21 Jun 2011, 08:42 PM
This assumes you can access the UI thread.

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.
0
Ivan Todorov
Telerik team
answered on 24 Jun 2011, 02:57 PM
Hello Chris,

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
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Mark
Top achievements
Rank 1
answered on 01 Jul 2011, 11:15 PM
I just made a static variable and got access to it.

I like your idea though. I never thought about doing that.
0
RTA
Top achievements
Rank 1
answered on 28 Mar 2014, 02:53 PM
Ivan,

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
0
George
Telerik team
answered on 02 Apr 2014, 11:36 AM
Hello 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.

 
0
Clara
Top achievements
Rank 1
answered on 07 Jul 2017, 12:20 PM

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!      

0
Hristo
Telerik team
answered on 10 Jul 2017, 08:13 AM
Hello Clara,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Clara
Top achievements
Rank 1
answered on 17 Jul 2017, 11:45 AM

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!

0
Hristo
Telerik team
answered on 18 Jul 2017, 10:22 AM
Hi Clara,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mahasiswa
Top achievements
Rank 1
answered on 05 Jan 2018, 06:34 AM
How to solve laptop hank ?
0
Hristo
Telerik team
answered on 05 Jan 2018, 09:00 AM
Hi Mahasiswa,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DesktopAlert
Asked by
pmoney pmoney
Top achievements
Rank 1
Answers by
pmoney pmoney
Top achievements
Rank 1
Jonathan Hylton
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Ivan Todorov
Telerik team
Mark
Top achievements
Rank 1
RTA
Top achievements
Rank 1
George
Telerik team
Clara
Top achievements
Rank 1
Hristo
Telerik team
Mahasiswa
Top achievements
Rank 1
Share this question
or