Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » RCP Stop execution of Runnable
RCP Stop execution of Runnable [message #498307] Mon, 16 November 2009 12:14 Go to next message
Juan is currently offline JuanFriend
Messages: 29
Registered: July 2009
Junior Member
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
Re: RCP Stop execution of Runnable [message #498319 is a reply to message #498307] Mon, 16 November 2009 13:28 Go to previous messageGo to next message
Heiko Ahlig is currently offline Heiko AhligFriend
Messages: 62
Registered: July 2009
Member
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
>
>
Re: RCP Stop execution of Runnable [message #498349 is a reply to message #498319] Mon, 16 November 2009 13:44 Go to previous message
Juan is currently offline JuanFriend
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
>>
>>
>
Previous Topic:Have to manually start org.eclipse.runtime in product
Next Topic:Splash screen freezes often in application based on Eclipse
Goto Forum:
  


Current Time: Fri Apr 26 03:03:04 GMT 2024

Powered by FUDForum. Page generated in 0.02733 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top