简体   繁体   中英

Set MailItem readonly while a ProgressBar is shown (Outlook Add-In by VSTO)

I'm creating an Add-In for Outlook in C# with VSTO.

Before sending a MailItem some special tasks will be done within the send-event. While this tasks are done, a modal form with a progress bar will be shown. That works fine. But while the progress bar is shown, the user cannot interact with Outlook. Whole Outlook is frozen. -> I want that the user can interact with Outlook while the tasks are done on the MailItem to be send.

So I created a new thread for the special tasks including showing the progress bar. Following steps will be done in the send-event:

Check a bool variable if the tasks were already done.

  1. If tasks aren't done yet, sending will be canceled and a new thread will be created and started for the tasks.
  2. After the tasks are done, a bool variable will be set into true (= tasks were already done).
  3. Also the send-method of the Mailitem will be called.

This also works fine. But then the modal form with the progress bar isn't modal anymore.. The user can interact with Outlook (good!). But he can also interact with the MailItem while the tasks are running and the progress bar is showing (not good!)...

So question is, how can I block the MailItem, set it into readonly or something different to avoid that the user can modify the MailItem while showing a progress bar?

You just need to specify the parent window handle (of the opened inspector window) to the ShowDialog method. In that case users will not be able to interact with the opened email until the progress bar is hidden.

An instance of the Inspector window can be cast to the IOleWindow interface where you can get the window handle. See the IOleWindow::GetWindow method for more information.

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