I am developing a java project where an external microcontroller device is connected via a serial port to a computer. I have a wait dialog in a java application waiting for a command to execute on a microcontroller. If the microcontroller does not respond within 10 seconds, the application is turned off.
The problem is that some commands run too fast and the microcontroller responds before the wait dialog is activated. This causes the application to shut down after ten seconds.
Here is the first idea that I decided to wait for the dialog box to appear:
new Thread() {
public void run() {
while (!Main.mainFrame.waitDialog.isVisible()) {}
Main.usbManager.start();
}
}.start();
But the application gets stuck in the while loop and the wait dialog is displayed, but if I add some random sentence to the while loop, for example System.out.flush();, it works, and when the dialog is visible, the program will exit the while loop.
How can I wait for the dialog to be visible?
thank
source
share