PC Review


Reply
Thread Tools Rate Thread

Closing form while processing

 
 
John
Guest
Posts: n/a
 
      31st Dec 2008
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


 
Reply With Quote
 
 
 
 
Josip Medved
Guest
Posts: n/a
 
      31st Dec 2008
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
 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      31st Dec 2008
On Dec 31, 5:54*am, Josip Medved <jmed...@jmedved.com> wrote:
> 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


To build on this, .NET allows you to create a seperate thread and set
the IsBackgroundThread (or something like that) property to allow the
Application to wait for that thread to finish before it dies. This
should allow your form to close, and for the loop to continue on in
the background, and finally the application would die after the
background thread was finished.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
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
Closing form while processing John Microsoft VB .NET 2 31st Dec 2008 12:58 PM
Closing a form error 2585 This action cannot be carried out while processing a form or report event SDLittle13@gmail.com Microsoft Access Form Coding 4 11th Mar 2007 05:58 PM
Firewall is closing open ports when GPO processing =?Utf-8?B?SmFuIEVyaWtzc29u?= Windows XP Networking 0 2nd Oct 2006 09:21 PM
Need to do pre processing before closing outlook Bhushan Navare Microsoft Outlook 0 18th Feb 2005 02:23 PM
Closing Cmd window after batch processing GeorgeMar Microsoft Access VBA Modules 1 25th Feb 2004 02:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:44 AM.