A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Progress Bar pattern



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 23rd 09, 04:44 PM posted to microsoft.public.outlook.program_addins
Craig Buchanan[_2_]
external usenet poster
 
Posts: 12
Default Progress Bar pattern

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  
Old January 23rd 09, 06:13 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Progress Bar pattern

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  
Old January 23rd 09, 10:37 PM posted to microsoft.public.outlook.program_addins
Craig Buchanan[_2_]
external usenet poster
 
Posts: 12
Default Progress Bar pattern

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 08:21 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.