PC Review


Reply
Thread Tools Rate Thread

Cancelling current activity in progress indicator

 
 
Dmitry Shaporenkov
Guest
Posts: n/a
 
      6th Sep 2003
Hi all,

in my application I want to implement a progress
indicator which has 'Cancel' button allowing to interrupt
the current activity. What is the best way to do such a
thing? I'm considering the following variant:

The progress indicator is created on demand on the
separate thread and stored in the local memory of the
thread that has initiated its creation ('initiating
thread'). The progress indicator also stores a reference
to the initiating thread. When a user clicks 'Cancel'
button, a delegate is executed on the initiating thread
that throws an exception, so that it can be handled
somewhere on the initiating thread.

The purpose of creating progress indicator on a separate
thread is that it will be unable to handle windows
messages (like clicking 'Cancel') if it is created on the
initiating thread.

Am I right or I'm reinventing the wheel and there is an
easier way? I would prefer simpler design, but I'm not
competent enough in WinForms to figure it out.

Thanks in advance,
Dmitry
 
Reply With Quote
 
 
 
 
Jerry Ham
Guest
Posts: n/a
 
      6th Sep 2003
It sounds like you have that backwards. You normally want to have your GUI
thread NOT be the one that is in a tight loop doing the "work" - you want
your worker thread to be doing that. Then, your cancel button can be in your
GUI thread as it should be and won't have any problem responding to the
click event.

From what it sounds to me like you are trying to do, you would be leaving
most of your GUI unresponsive (can't resize, minimize, won't redraw when
another window covers it temporarily, etc.). Moving the work to the other
thread fixes all of these things.

Jerry

"Dmitry Shaporenkov" <(E-Mail Removed)> wrote in message
news:286301c3745e$fd652d00$(E-Mail Removed)...
> Hi all,
>
> in my application I want to implement a progress
> indicator which has 'Cancel' button allowing to interrupt
> the current activity. What is the best way to do such a
> thing? I'm considering the following variant:
>
> The progress indicator is created on demand on the
> separate thread and stored in the local memory of the
> thread that has initiated its creation ('initiating
> thread'). The progress indicator also stores a reference
> to the initiating thread. When a user clicks 'Cancel'
> button, a delegate is executed on the initiating thread
> that throws an exception, so that it can be handled
> somewhere on the initiating thread.
>
> The purpose of creating progress indicator on a separate
> thread is that it will be unable to handle windows
> messages (like clicking 'Cancel') if it is created on the
> initiating thread.
>
> Am I right or I'm reinventing the wheel and there is an
> easier way? I would prefer simpler design, but I'm not
> competent enough in WinForms to figure it out.
>
> Thanks in advance,
> Dmitry



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Sep 2003
Hello,

"Dmitry Shaporenkov" <(E-Mail Removed)> schrieb:
> in my application I want to implement a progress
> indicator which has 'Cancel' button allowing to interrupt
> the current activity. What is the best way to do such a
> thing? I'm considering the following variant:
>
> The progress indicator is created on demand on the
> separate thread and stored in the local memory of the
> thread that has initiated its creation ('initiating
> thread'). The progress indicator also stores a reference
> to the initiating thread. When a user clicks 'Cancel'
> button, a delegate is executed on the initiating thread
> that throws an exception, so that it can be handled
> somewhere on the initiating thread.


Untested:

http://www.codeproject.com/cs/miscct...ressdialog.asp

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IE 6 web page surfing indicator or activity indicator =?Utf-8?B?a25lZWR0b25vc2U=?= Windows XP Internet Explorer 1 5th Nov 2006 01:57 PM
Progress Indicator =?Utf-8?B?Q2FsbHlwc28=?= Microsoft Outlook Discussion 2 17th May 2006 06:00 PM
Progress Indicator =?Utf-8?B?Q2FsbHlwc28=?= Microsoft Outlook Installation 0 17th May 2006 05:51 PM
Progress Indicator? Anthony Slater Microsoft Excel Misc 3 3rd Sep 2004 02:35 PM
IE Activity Indicator =?Utf-8?B?c2NobWllZw==?= Windows XP Internet Explorer 2 3rd Feb 2004 04:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 AM.