Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How can I both update a control and do other works ?
How can I both update a control and do other works ? [message #459667] Wed, 06 December 2006 02:32 Go to next message
Eclipse UserFriend
Hi all,
I am confused in updating a control of my editor. It is a TextBox, I just want to update it through a Thread:
---------------------------------------------
myeditor.getSite().getShell().getDisplay().asyncExec (new Runnable () {
public void run ()
{
int count = 0;
while(true){
editor.textMessageSequences.append("hello");
count++;
if (count == 50000) break;
}
}
});
----------------------------------------------
When I run this code, I can not focus other control. How can I both update a control and do other works ? Thanks a lot.
Re: How can I both update a control and do other works ? [message #459669 is a reply to message #459667] Wed, 06 December 2006 03:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: guefeld.spammerslammer.com

Hi hong hai, (speak it loud)

To me it seems a matter of the underlying windowing system.
In general you have a thread which collects data or calculation results into
an array or list structure and then passes it to the user interface thread
for displaying
In your case it seems to me, that the event loop of the main ui thread never
gets a chance to dispatch user input events as clicking on another widget
because it is under hefty bombardement of your append() calls.
Maybe display.wake() called inside your append-loop would do it... Thus pass
the display object with the constructor of your runnable into your thread.

Just my 2 cents
G
Re: How can I both update a control and do other works ? [message #459677 is a reply to message #459667] Wed, 06 December 2006 07:23 Go to previous messageGo to next message
Eclipse UserFriend
hong hai wrote:
> Hi all,
> I am confused in updating a control of my editor. It is a TextBox, I just want to update it through a Thread:
> ---------------------------------------------
> myeditor.getSite().getShell().getDisplay().asyncExec (new Runnable () {
> public void run ()
> {
> int count = 0;
> while(true){
> editor.textMessageSequences.append("hello");
> count++;
> if (count == 50000) break;
> }
> }
> });

1) asyncExec(*) just posts the runnable object to the UI thread ...
you're not in a separate thread.

2) you probably want to run your Runnable in a new thread (new
Thread(runnable).start();), and then wrap your calls to
editor.textMessageSequences in an asyncExec(*)

3) you probably want a Thread.sleep(*) in your loop, even a small one.

Later,
PW
Re: How can I both update a control and do other works ? [message #459728 is a reply to message #459667] Wed, 06 December 2006 21:39 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your advice, your mean is:
-----------------------------------------
public class MyRunnable implements Runnable
{
public RuntimeEditor p;
public void run() { p.getSite().getShell().getDisplay().syncExec(new Runnable(){
public void run(){
while (true){ p.textMessageSequences.append("hello"); p.getSite().getShell().getDisplay().wake();
Thread.sleep(500);
}
}});
}
}
//And then
MyRunnable r = new MyRunnable();
r.p = this; //this : is my EditorPart
Thread t = new Thread(r);
t.start();
--------------------------------------------
I don't see any different result. Could you please give me just a small code sample ?...Thanks all.
Re: How can I both update a control and do other works ? [message #459732 is a reply to message #459667] Wed, 06 December 2006 22:08 Go to previous message
Eclipse UserFriend
I find out how to do it
----------------------------------------
public class MyRunnable implements Runnable
{
public RuntimeEditor p;
public void run() {
Display dis = p.getSite().getShell().getDisplay();
while(true){
dis.asyncExec(new Runnable(){
public void run(){
p.textMessageSequences.append("hello");
}
});
try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}
}
}
}
--------------------------------------------------------
Oh,astonishingly enough, very simple...Thanks a lot
Previous Topic:Parameterized view or editor
Next Topic:Spring Plugin and NoClassDefFound
Goto Forum:
  


Current Time: Fri Mar 21 20:37:14 EDT 2025

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

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

Back to the top