473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I need an abort button

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?
--
mark b
Dec 6 '05 #1
5 2878
dgk
On Tue, 6 Dec 2005 05:09:02 -0800, "mark"
<ma**@discussions.microsoft.com> wrote:
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.

Dec 6 '05 #2

dgk wrote:
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.

Dec 6 '05 #3

--
mark b
"Brian Gideon" wrote:

dgk wrote:
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.

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.

Dec 6 '05 #4
"mark" <ma**@discussions.microsoft.com> schrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 6 '05 #5
I'm OK now guys thanks.
--
mark b
"mark" wrote:

--
mark b
"Brian Gideon" wrote:

dgk wrote:
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.

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.

Dec 6 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wayne M J | last post by:
I have been using threads on and off, but I am always coming across a situation that baffles me: where is the best place to put a Thread.Abort() call? I have a form, when the button event is...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
6
by: LP | last post by:
Hi, I am starting a new thread from the main UI thread. If users clicks cancel button, the thread is aborted: workerThread.Abort(); ThreadAbort Exception is handeled in the worker thread: ...
2
by: yxq | last post by:
Hello There is a thread in my form, when user click the Close button on form, i want to abort the thread, then close the form, but my code seem not to work. Private Sub frm_Closing(ByVal sender...
6
by: Sakharam Phapale | last post by:
Private myThread As Thread Sub cmdStart_Click() myThread = New Thread(AddressOf PlayAudio) myThread.Start End Sub Sub PlayAudio() Open wave file Play wave file
0
by: nidhig | last post by:
Hi I am trying to implement the Abort functionality in progress bar control. Scenario is like this. I have a web application which performs a very long computation process. This computation...
0
by: nidhig | last post by:
Hi I am trying to implement the Abort functionality in progress bar control. Scenario is like this. I have a web application which performs a very long computation process. This computation...
0
by: Matt | last post by:
I'm attempting to load a form, query a database, and update a progress bar on the same form. I want the form to load and activate/enable the form's cancel button while the code continues to...
3
rsrinivasan
by: rsrinivasan | last post by:
Hi all, I am using the below html page. It displays a messagebox when the page is loaded. But the messagebox has 3 button abort,retry, ignore. But i want only abort and ignore button. what should...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.