Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pop-up notification for Outlook Add-in (calling Form.Show() from background thread issue)

My Outlook 2010 add-in (using VSTO) does some web-service calls in a different thread when a mail is sent. I'd like to display a small non-modal pop-up notification (like those of Skype/yahoo/Windows live messenger) displaying the result of the web-service call.

I was trying to customize the Notification Window project as per my requirements. It seems to work fine when called from a click event handler of a form of my add-in using the following code:

private void btnOk_Click(object sender, EventArgs e)
{
    PopupNotifier notifier = new PopupNotifier();
    notifier.DisplayNotification("Test");
}

However, when the same method notifier.DisplayNotification("Test") is called from the background thread doing the web-service call, the notifier hangs; Its form is displayed on screen, but no text, color or animation seems to work. It just sits there until Outlook is closed.

I've done some searching and found that this might happen since the notifier is using the Show() method instead of ShowDialog() for displaying its form. And since I don't want a modal dialog for the pop-up notification, I can't change the method to ShowDialog() either.

According to other articles, I've also tried calling the method using backgroundWorkers, delegates, MethodInvoker, etc. but could not get the desired result.

However, while trying the above, I noticed that the same happens for not only the pop-up notifier, but any simple form. If I create it in the background thread and call the Show() method, it just gets stuck, whereas in the same situation ShowDialog() seems to work fine.

Any idea on how I could fix this would be greatly appreciated.

like image 781
FahimH Avatar asked Nov 03 '22 13:11

FahimH


1 Answers

I eventually managed to solve the issue using the TaskbarNotifier project.

like image 72
FahimH Avatar answered Nov 15 '22 05:11

FahimH