You loop will end when the Thread gets interrupted. So all you would have to do was interrupt the thread running the long loop:

That will cause an InterruptedException the next time the thread sleeps, and break out of the loop - ending the Thread.

Another way might be to introduce a boolean value which you check on in the infinite loop, and only keep running while it is true. You then use a method to set that value to false, which kills the thread. Perhaps something like this:

Steve

Bob Lawson
Ranch Hand

Joined: Jul 20, 2010
Posts: 34

posted Oct 27, 2010 17:09:20

0

Steve,

That is EXACTLY what I was looking for. Thank you SO MUCH!!

Bob

Bob Lawson
Ranch Hand

Joined: Jul 20, 2010
Posts: 34

posted Oct 28, 2010 09:01:02

0

Well, I thought it was exactly what I wanted. But now it turns out that it must run as a new thread, rather than run under the current thread as above. How would you do that?

Bob Lawson wrote:Well, I thought it was exactly what I wanted. But now it turns out that it must run as a new thread, rather than run under the current thread as above. How would you do that?

What do you mean? What has to run as a new thread? The run() method can run on any given thread (assuming the class is a Runnable). The thread which wants to cancel the task needs to have access to the same object and calls the cancelWidgets() method, but can also be called from any thread (presumably not the same one as does the processing).

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com