Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Confusing code(Thread progress monitoring)
Confusing code [message #769372] Wed, 21 December 2011 22:59 Go to next message
Bill Brandley is currently offline Bill BrandleyFriend
Messages: 12
Registered: October 2011
Junior Member
I wrote a program and I got it to work but don't know why it works. Also, I don't think that what I did is the correct way to code.

Here's what is going on.

I click on a RUN button and execute the code below which is in the MouseUp event handler.

1-2: A thread object is initialized and the thread is started.
5 The RUN button is disabled.
6-7 A LABEL is displayed that will be updated to indicate file name as the thread progresses.
9-20 This is the code I don't understand:

In it, I fetch the latest file name from the thread (line 14) and update the LABEL (line 17).

It runs correctly (for the most part). The code in lines 9-20 I do not understand nor do I think this is the recommended method to monitor the progress of a thread.

1 runningScan = new Thread(scanFiles);
2 runningScan.start();
3
4
5 btnRun.setEnabled(false);
6 lblProgress.setVisible(true);
7 lblProgress.setText("");
8
9 while(runningScan.isAlive()) {
10 getShell().getDisplay().sleep();
11
12 while(getShell().getDisplay().readAndDispatch()) {
14 String currentFile = scanFiles.getCurrentFileName();
15
16 if (currentFile != null) {
17 lblProgress.setText(currentFile);
18 }
19 }
20 }
21
22 btnRun.setEnabled(true);
23 lblProgress.setVisible(false);

I couldn't find an idle loop in which I could monitor the progress of the thread and I said that this works for the most part since I found that the LABEL will not update if I add any additional controls to the window though this is an unrelated problem.

I'd appreciate any insight that can be provided.

Thanx,
Bill
Re: Confusing code [message #769859 is a reply to message #769372] Thu, 22 December 2011 19:51 Go to previous message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
I'm sorry, but this is off topic for this forum. This forum is should only be used for WindowBuilder specific questions and problems.

I would recommend the Eclipse SWT, RCP or Newcomer forums for general UI questions.
Previous Topic:Change which components appear on top in WindowBuilder editor
Next Topic:Problem with databinding
Goto Forum:
  


Current Time: Thu Apr 18 18:37:02 GMT 2024

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

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

Back to the top