Cancelling process with Cancel event

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

How can I cancel all running processes in my application when I click on the
Cancel button? When the Run button's clicked, it creates an instance of a
specified class and runs a method that reads each line of a file, processes
it , and writes it. With the Cancel button, I'd like to cancel this method.

Is this possible?

Thanks.
 
----- VM wrote: ----

How can I cancel all running processes in my application when I click on th
Cancel button? When the Run button's clicked, it creates an instance of
specified class and runs a method that reads each line of a file, processe
it , and writes it. With the Cancel button, I'd like to cancel this method

Is this possible

Yes, it's easy if you use a separate thread to perform the processing. For example, when the Run button is clicked you can start a new thread and that thread creates the instance of your specified class and proceeds to read the file and process it

In the meanwhile, your main thread can still respond to UI events and when the Cancel button is clicked you can either; 1) abort the worker thread you created before, or 2) set a flag that the worker thread examines that will indicate that it should abort its processing more gracefully

-- T
 
Back
Top