I need an abort button

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

Guest

I have an application with several methods, many of which perform matrix
computations. Occasionally the methods will take too long to complete and the
user may want to abort and do something else.

I envision a "abort" button which raises an event but I am uncertain how to
implement stopping whatever procedure happens to be active. Is there some
global "halt whatever happens to be executing" technique?
 
I have an application with several methods, many of which perform matrix
computations. Occasionally the methods will take too long to complete and the
user may want to abort and do something else.

I envision a "abort" button which raises an event but I am uncertain how to
implement stopping whatever procedure happens to be active. Is there some
global "halt whatever happens to be executing" technique?

Looks like a perfect candidate for threading. Start a thread passing
it the address to your matrix calculation subroutine, and if the user
hits the Abort button, you kill the thread.

I'm no expert on threading so better advice is likely to follow, but
one of many cautions is that only the UI thread is allowed to touch
the controls on a form. Not that other threads can't do so but don't
do it because it will fail on some random basis that you will never be
able to debug.
 
dgk said:
Looks like a perfect candidate for threading. Start a thread passing
it the address to your matrix calculation subroutine, and if the user
hits the Abort button, you kill the thread.

Yes. Theading is the way to go. However, instead of indiscriminately
killing the thread I'd opt for having the thread check a flag that
indicates whether or not it should continue the calculation. Killing
threads via Thread.Abort or whatever can cause other problems.
I'm no expert on threading so better advice is likely to follow, but
one of many cautions is that only the UI thread is allowed to touch
the controls on a form. Not that other threads can't do so but don't
do it because it will fail on some random basis that you will never be
able to debug.

Use Control.Invoke to marshal the execution of a delegate onto the UI
thread.
 
--
mark b


Brian Gideon said:
Yes. Theading is the way to go. However, instead of indiscriminately
killing the thread I'd opt for having the thread check a flag that
indicates whether or not it should continue the calculation. Killing
threads via Thread.Abort or whatever can cause other problems.


Use Control.Invoke to marshal the execution of a delegate onto the UI
thread.

Now I'm lost. The thread abort worked but I can only use it once. If I try it again I get: Thread is running or terminated; it can not restart.
 
mark said:
I have an application with several methods, many of which perform matrix
computations. Occasionally the methods will take too long to complete and
the
user may want to abort and do something else.

I envision a "abort" button which raises an event but I am uncertain how
to
implement stopping whatever procedure happens to be active. Is there some
global "halt whatever happens to be executing" technique?

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top