User controlled exit from processing loop

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

In my windows forms application, I have a process which takes some time to
complete. I have a nice progress bar showing how far through the process is,
but I want to enhance this with a "Press ESC to abort" statusbar message.
But how can I actually implement this hotkey-escape-from-loop functionality
?
 
Tried subscribing to KeyDown event on my form, and in there setting a
private bool variable "escaped" to true, testing this in my loop. This works
"sometimes" - only when I focus on my form by clicking on it's taskbar entry
(when I just focus by clicking on the window KeyDown is not fired!).
 
I may just be talking to myself here but ....

The KeyDown approach seems to be more reliable when I set the KeyPreview
property of the form to True.
 
Back
Top