Skip to content

Commit

Permalink
fix: Fix bug in recreating thread
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukhqasim committed Oct 14, 2017
1 parent e3ab7bf commit e188d91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.shahrukhqasim.ties.label;

import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class Controller {
public Canvas canvas;
double scale = 1;
Timer updater;
Task task;
public Label zoomLabel;
public Label fileLabel;
private IOManager ioManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,23 @@ void load() {
controller.canvas.setWidth(controller.image.getBoundingBox(controller.scale).getWidth());
controller.canvas.setHeight(controller.image.getBoundingBox(controller.scale).getHeight());

Task task = new Task<Void>() {
@Override
public Void call() throws Exception {
while (true) {
Platform.runLater(new Runnable() {
@Override
public void run() {
controller.redraw();
}
});
Thread.sleep(100);
if (controller.task == null) {
controller.task = new Task<Void>() {
@Override
public Void call() throws Exception {
while (true) {
Platform.runLater(new Runnable() {
@Override
public void run() {
controller.redraw();
}
});
Thread.sleep(100);
}
}
}
};
Thread th = new Thread(task);
};
}
Thread th = new Thread(controller.task);
th.setDaemon(true);
th.start();
controller.fileLabel.setText(imagePath);
Expand Down

0 comments on commit e188d91

Please sign in to comment.