03-04-2012 08:52 AM
Attached file is a zipped project which demonstrates a problem which i would like help with.
If a user presses the command buton the value is updated and a timed delay routine is started. This is ok for one press at a time.
If the user presses the button several times (quickly) the value indicated shows the last value whilst the delayed loop is running but on completion the previous values in the sequence are displayed.
Please can anyone help to explain this and provide a solution.
Dimming/disabling the control is not option as the user needs full control
03-04-2012 03:13 PM
Is this the same topic as here - or what is the difference?
03-05-2012 02:09 AM
As Wolfgang has already noted, this thread seems the prosecution of the old one he linked: it is very advisable that questions are not divided into several threads as it becomes difficult for us to follow them.
Given this, the behaviour of the program is clear if you think of the execution of the program. Every time you press the button yout Routine () is called with a different value and runs a loop. Every time, while in the loop it stops other running loops (adding a ProcessSystemEvents () does not alter this, as loop prosecution is not a UI or system event). When the last loop terminates it frees the last-but-one, which eventually will terminate and so on. That's why you see 'Value' content decreasing from the initial one.
What you absolutely need to do is to determine which actions are legal in every moment and what to do in every situation. You say the user needs full control, but is it legal for him to fire the routine more than once (I suppose the loop actually mimics some long-lasting operation like measure, data analysis or so)? What is the function supposed to do if concurrently running two or more times? Can it actually do so? May there be conflicts on shared resources / data or not? You said nothing about the function scope, so you'll have to answer to these questions yourself and then reconsider the code to make it operable in the situation you have to address. Please ask yourself also if user desires can actually be addressed or if they are simply too much for the system to handle them properly.
03-05-2012 02:57 AM
Thanks for the response.
Yes this is the same problem as the other thread , I was trying to attch code but i kept getting an error on the website (file attachments don't match).
The loop function is used to control an antenna positioner, the user should be able to press a move button to start the movement. the loop function is used to check whether the position has been reached, a fault occured or a time out. For each press of the move button the distance of the required moves is incremented.it is not possible to dim the control while movement is occuring as the user may want to move further.
Would a GetUserEvent or Queue UserEvent be a better approach than using callbacks?
It quite weird watching an antenna move to its final position then reverse back.
03-05-2012 03:26 AM
Why not simply having a global variable with the target position and a separate process to control the position (possibly in a separate thread)?
User action could then be limited to change the target value and the movement process loop until the position matches with the target.
If using multithreading you could avoid the use of a global variable by passing the target value via a thread safe queue.
03-05-2012 06:29 AM
Global variable works
Many Thanks