Computer Science Canada Can't click GUI Buttons if a loop is running - Traffic Light System |
Author: | ShifatT [ Thu Feb 28, 2013 5:37 pm ] |
Post subject: | Can't click GUI Buttons if a loop is running - Traffic Light System |
What I am doing: I am trying to make a Traffic Light System for class. Problem : When a loop is running, I cannot click any buttons until the loop ends. Eg: If I start Auto-Mode, I cannot click any buttons until the for-loop ends. What I did: Remove the loop - Which defeated the purpose of some of the features of the program Code: Attatched Turing Version : 4.1.2, 4.0.5 at School.[/u] |
Author: | Tony [ Thu Feb 28, 2013 6:35 pm ] |
Post subject: | RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System |
programs are linear and do one thing at a time. If the program is busy spending time inside of for-loop, it will not get to the code that handles the buttons (or anything else) for a while. The solution -- don't block on long running loops. |
Author: | ShifatT [ Thu Feb 28, 2013 7:58 pm ] |
Post subject: | Re: RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System |
Tony @ Thu Feb 28, 2013 6:35 pm wrote: programs are linear and do one thing at a time. If the program is busy spending time inside of for-loop, it will not get to the code that handles the buttons (or anything else) for a while.
The solution -- don't block on long running loops. So I just leave it as it is? |
Author: | Tony [ Thu Feb 28, 2013 9:22 pm ] | ||||
Post subject: | RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System | ||||
If you understand what's going on and that is acceptable to you. Basically in a scenario such as
B has to wait for A to completely finish. An alternative is to design your code to be along the lines of
This way A and B alternate taking steps, and both get to make some progress, without waiting for the other for too long. |