newbie: Help closing window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need som help safely closing a window. I have an application which loops
through all the files in a designated folder and runs OCR on them. The loop
to do the OCR work is in its own method. The app runs fine unless I try to
close the window before the loop is finished. Any suggestions on how I can
safely end my loop and close the window.

Any help would be greatly appreciated.

Chris
 
You can prevent the close by using the forms Closing() method handler.

do your test to see that safe to close...otherwise perform
e.Cancel = true;
Br,

Mark.
 
Mark Broadbent said:
You can prevent the close by using the forms Closing() method handler.

do your test to see that safe to close...otherwise perform
e.Cancel = true;
Br,

Mark.

Or set a flag to abort the loop (that the loop checks every so often) and
then cancel the Close. Have the loop call the close methods when it is safe
to do so :)

Mythran
 
Pretty inefficient to have the loop checking every so often, would be better
for the check to be done in the closing event (which would still need to be
handled anyways to prevent a close). A flag could be used which can be set
once loop has finished, the closing event handler would need to test this
flag.
 
Hi man,
Have a flag on your form set to false, in the event form1_Closing set the
flag to true, and inside your loop check the flag , if is true break;
Hope that helps
 
Mark said:
Pretty inefficient to have the loop checking every so often, would be better
for the check to be done in the closing event (which would still need to be

Agree. But I don't think that one 'check' in OCR loop could make a
difference... OCR is pretty resource consuming anyway ;-)
handled anyways to prevent a close). A flag could be used which can be set
once loop has finished, the closing event handler would need to test this
flag.

But it would mean that the window can be closed only in case loop's
finished. I think the question here was "how to close a window and don't
care if the loop is done or not?".

What I could suggest is to perform a loop in its own thread. It's very
easy then to manage this thread (suspend, exit, change priority, etc.).
In this case you can exit this thread while handling closing event. I
guess this could work...
 
inline comments...

br,
mark.
TroLoo said:
Agree. But I don't think that one 'check' in OCR loop could make a
difference... OCR is pretty resource consuming anyway ;-)

One check in a loop means one check per loop = many checks.
But it would mean that the window can be closed only in case loop's
finished. I think the question here was "how to close a window and don't
care if the loop is done or not?".

Yes true. That is what I believed was wanted but I can see that what you
suggest might be potentially what he wants... I think he needs to clarify
this. (p.s. if you are going to quote "" please use the original quote not
your interpreted text!)
What I could suggest is to perform a loop in its own thread. It's very
easy then to manage this thread (suspend, exit, change priority, etc.). In
this case you can exit this thread while handling closing event. I guess
this could work...

Hmmmm. Possibly. I guess it depends on what behaviour newbie is really
wanting.
***Newbie Please Clarify****
 
Mark Broadbent said:
inline comments...

br,
mark.


One check in a loop means one check per loop = many checks.

I meant one check every so many iterations...even so, 1 check for loop
wouldn't be so bad...if you think about it...it's just checking a single
boolean variable for True and then would perform the "quit" code required to
gracefully stop the OCR process....only thing that it would do every loop
would check for True.

:)

Mythran
 
Hi Mythran. Not too sure how you are going to do (as you put it) one check
every so many iterations, such a construct is gonna have overhead. But
you're right a test against a bool is probably not gonna cause too much
trouble. However it's not really the most efficient way to handle the
desired behaviour.

I think is TroLoo is right in what clsmith66 wants, then a thread would
probably be the way to go. The loop should indicate when it is finished so
the form knows when to close gracefully or do it's forcefull bits and
pieces.

Nether-the-less, I'm guessing clsmith66 has probably derived a way to go
forward from everyone's input in this thread including yours (and hopefully
mine too).

Br,

Mark.
 
Back
Top