Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cancel a long running process
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00945712
Message ID:
00945719
Vues:
17
Windows forms work with a single thread of execution by default. If that single thread is busy executing a method on the business object then your windows events will get queued up in the message queue until the method is done processing (the dreaded hourglass icon).

There are a couple of things you can do. If there is a convenient place in your long running loop, you may be able to place an Application.DoEvents in the loop which will allow the message queue to get serviced. I think a better way is to execute the business object's method on a worker thread (see Thread.Start) and let it raise events that the main ui thread can listen to. Then you could send the worker thread a cancel message which would allow it to cancel gracefully.

Be aware that the only thread that updates a ui control should be the one that created it. Hopefully that will give you enough background to research these ideas on the net. If I can dig up some code i'll post it.


>In my application I have several calculation routines that can run for a long time depending on the number of records being processed. I want to give the users the ability to "cancel" processing if they want.
>
>I have a form with some text, a progress bar, OK and Cancel buttons. Clicking on the OK button will call a calculation method in a business object. I want to use the escape key as the cancel.
>
>I have added code to the individual controls and the form's KeyDown event to check for the escape key. I have also tested the form's KeyPreview property to override the individual controls. This all works great when the form has focus, but once I click the OK button and the business object takes over, the KeyDown event is no longer recognized.
>
>My question is, do I need to do something in the processing loop to have it check for a KeyDown during each iteration?
>
>Thanks in advance for any help!
>
>Kind Regards,
>
>Mat
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform