On 31 pro, 10:31, "John" <i...@nospam.infovis.co.uk> wrote:
> Hi
>
> I have a while loop in a win form code. Also a close button on the form
> calls Me.Close. How can I let the user close the form using the close button
> even though the loop is still running? Right now pressing Close button waits
> for loop to finish and then closes the form.
>
> Thanks
>
> Regards
You should move processing of that task to separate thead
(BackgroundWorker, ThreadPool or
your own thread). There is little bit more work involved since there
is always issue of getting results
and displaying them on form.
I would recommend that you use BackgroundWorker since it will change
your code only minimally.
Just intercept FormClosing action and then do your own loop canceling
logic (BackgroundWorker
can support async cancel also).
--
Josip Medved
http://www.jmedved.com
http://medo64.blogspot.com