|
|
Re: RCP Stop execution of Runnable [message #498349 is a reply to message #498319] |
Mon, 16 November 2009 13:44 |
Juan Messages: 29 Registered: July 2009 |
Junior Member |
|
|
Ey Heiko! Thanks a lot for your fast answer.
Unfortunately your proposal would not work in my case because I can't
modify the task method (it's other partner code). I simply want to stop
the thread that runs that method, but I dont know how.
The situation is the following:
class RunCode implements IRunnableWithProgress{
public void run(IProgressMonitor monitor) throws
InvocationTargetException, InterruptedException {
monitor.beginTask("do something ..."
,IProgressMonitor.UNKNOWN);
other_partner_read_only_method(); //<-- problem: I can't throw
InterruptedException here
monitor.done()
}
//invoked when monitor cancel button is pressed
//HOW IMPLEMENT THIS TO STOP RUNCODE.RUN() ???
public void stopRunCode(){
}
I want to stop the Runnable from a stopRunCode() method, invoked when
the monitor is monitor.isCancelled equals true-checking that I do from a
thread that continuosly is checking for it)
Heiko Ahlig escribió:
> Inside the runnable you cancel it like this:
>
> @Override
> public void run(IProgressMonitor monitor) throws
> InvocationTargetException, InterruptedException {
> monitor.beginTask("do something ..."
> ,IProgressMonitor.UNKNOWN);
>
> // do something
>
> if(monitor.isCanceled()){
> throw new InterruptedException("Runnable was
> canceled.");
> }
> //do somthing more
>
> monitor.done();
> }
>
> if you want "cancel" it programmaticaly from outside you need only the
> monitor which is used inside the Runable.
>
> The monitor has a method monitor.setCanceled(true) and than you can
> stop it inside.
>
>
>
> Am 16.11.2009 13:14, schrieb Juan Miguel:
>> Hi There!
>
>>
>> *I have a "Run" button in my RCP app that launchs a task. This task code
>> is in a RunnableWithProgress so that I could see its progress and stop
>> it whenever I need.
>> When user clicks on "Run", then I run that runnable called "RunCode"
>> using:
>>
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(tru e,
>> true, RunCode); //I use it because the progress monitor if not doesn't
>> appear
>>
>> *the RunCode is:
>>
>> class RunCode implements IRunnableWithProgress{
>> ...
>> run(IProgressMonitor monitor){
>> monitor.beginTask("launching ...", IProgressMonitor.UNKNOWN)
>> //here goes the code of the task
>> taskActions();
>> monitor.done();
>> }
>> }
>>
>>
>> THE PROBLEM IS THAT i need to STOP the execution programmaticaly but I
>> dont know how to achieve it because the runnable has no methods to stop
>> it. Some help would make me happy :)
>>
>> Regards
>>
>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03741 seconds