简体   繁体   中英

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.

我最终设法使用TaskbarNotifier项目解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM