![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I need to display a progress meter, that accepts cancellation, during a
long-running process in my add-in. Originally, I planned to use the BackgroundWorker, but soon learned of the cross-threading issues that occur w/ Outlook. I've written a replacement, but I want to make sure that the pattern is a decent one. I created a progress form that contains the progress bar and a cancel button. the form has a public method that is use to update the progress bar's UI. it also has a Cancelled event that is triggered when the cancel button is clicked. In the long-running process, i create an instance of this form and delegate it's Cancelled event to another procedure. Each time a message is sent, i update the progress bar thru the popup's public method. doevents is called at the end of each loop. when the process is completed, i close the popup. in the deletegated Cancelled method, a module-level variable "CancellationPending" is set to true. This variable is checked in the loop mentioned above. if it is true, appropriate action is taken. Does this seem to be a reasonable approach? Thanks for your time, Craig Buchanan |
Ads |
#2
|
|||
|
|||
![]()
It seems reasonable.
A solution with a background thread would require marshaling the thread context of the background thread to the main addin thread. I usually get the main context after some Outlook UI is established, such as NewExplorer() and NewInspector(). I first call System.Windows.Forms.Application.DoEvents to prime the message pump (no thread context otherwise) and get the current context using System.Threading.SynchronizationContext.Current. I store that in a globally available SynchronizationContext object. I usually do this when I need to call into some ActiveX control from a separate thread, such as when populating a Web browser control from a WordMail thread in Outlook. When I need to call into that control I pass arguments to the control using an array of arguments and call the form with the control using System.Threading.SendOrPostCallback to post a callback. If the callback isn't null I set the SynchronizationContext to the previously stored global SynchronizationContext and use context.Send to send the callback the arguments. It's complex to establish and maintain, but in some cases it's the only way to do things. In your case for the progress control I'd do it the way you suggested. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Craig Buchanan" wrote in message ... I need to display a progress meter, that accepts cancellation, during a long-running process in my add-in. Originally, I planned to use the BackgroundWorker, but soon learned of the cross-threading issues that occur w/ Outlook. I've written a replacement, but I want to make sure that the pattern is a decent one. I created a progress form that contains the progress bar and a cancel button. the form has a public method that is use to update the progress bar's UI. it also has a Cancelled event that is triggered when the cancel button is clicked. In the long-running process, i create an instance of this form and delegate it's Cancelled event to another procedure. Each time a message is sent, i update the progress bar thru the popup's public method. doevents is called at the end of each loop. when the process is completed, i close the popup. in the deletegated Cancelled method, a module-level variable "CancellationPending" is set to true. This variable is checked in the loop mentioned above. if it is true, appropriate action is taken. Does this seem to be a reasonable approach? Thanks for your time, Craig Buchanan |
#3
|
|||
|
|||
![]()
Thanks Ken.
"Ken Slovak - [MVP - Outlook]" wrote in message ... It seems reasonable. A solution with a background thread would require marshaling the thread context of the background thread to the main addin thread. I usually get the main context after some Outlook UI is established, such as NewExplorer() and NewInspector(). I first call System.Windows.Forms.Application.DoEvents to prime the message pump (no thread context otherwise) and get the current context using System.Threading.SynchronizationContext.Current. I store that in a globally available SynchronizationContext object. I usually do this when I need to call into some ActiveX control from a separate thread, such as when populating a Web browser control from a WordMail thread in Outlook. When I need to call into that control I pass arguments to the control using an array of arguments and call the form with the control using System.Threading.SendOrPostCallback to post a callback. If the callback isn't null I set the SynchronizationContext to the previously stored global SynchronizationContext and use context.Send to send the callback the arguments. It's complex to establish and maintain, but in some cases it's the only way to do things. In your case for the progress control I'd do it the way you suggested. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Craig Buchanan" wrote in message ... I need to display a progress meter, that accepts cancellation, during a long-running process in my add-in. Originally, I planned to use the BackgroundWorker, but soon learned of the cross-threading issues that occur w/ Outlook. I've written a replacement, but I want to make sure that the pattern is a decent one. I created a progress form that contains the progress bar and a cancel button. the form has a public method that is use to update the progress bar's UI. it also has a Cancelled event that is triggered when the cancel button is clicked. In the long-running process, i create an instance of this form and delegate it's Cancelled event to another procedure. Each time a message is sent, i update the progress bar thru the popup's public method. doevents is called at the end of each loop. when the process is completed, i close the popup. in the deletegated Cancelled method, a module-level variable "CancellationPending" is set to true. This variable is checked in the loop mentioned above. if it is true, appropriate action is taken. Does this seem to be a reasonable approach? Thanks for your time, Craig Buchanan |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
config progress window | W-[_2_] | Outlook - Installation | 0 | December 30th 08 02:21 PM |
send/receive progress | Adam Bailey | Outlook Express | 2 | November 29th 07 11:42 PM |
Add-In for Progress Indicator | Callypso | Add-ins for Outlook | 0 | May 17th 06 06:11 PM |
Progress Indicator | Callypso | Outlook - Installation | 0 | May 17th 06 05:51 PM |
Changing the Progress Indicator | Callypso | Outlook and VBA | 1 | May 17th 06 05:48 PM |