Hi,
I have a Xojo project that has gone through many iterations, going all the way back to Real Basic in 1999. Recently, I tried building the program for Windows and was initially very pleased at how easy this seemed. But, then I realized that the Windows version wasn’t updating a list box in the user interface, something that had never been a problem on the Mac. Following various leads, I have been trying to incorporate a task to alleviate this problem. But, I have reached a point where I think that I need some help.
The major function of this program is to record readings from an instrument at regular time intervals (on the order of seconds), via a serial connection. As each measurement is made, it is entered into a listbox, and a progress bar is updated.
I have incorporated a task as a control in the window that contains the listbox, as well as a button that starts the run. And, I have managed to use the UpdateUI event to update the listbox. From initial experiments, this does seem to resolve the problems that I was seeing on Windows 10.
What I haven’t been able to figure out, however, is how to exit gracefully from the task and return control to the main thread of the program. Following the run, the window containing the listbox needs to be updated, and a graph is made from the contents of the listbox, using DataPlotClasses, from Roger Meier.
In the action for the button that starts the process, I have:
setUpRun// a method that sets things up for the run
kineticsTask.Run
Everything works with this, but nothing happens after the task completes, which makes sense. If I add a call to another method, like this:
setUpRun// a method that sets things up for the run
kineticsTask.Run
endRun// a method that should up date the window and call the plotting routine
Then, endRun starts as soon as kineticsTask.Run starts, which also makes sense, since the task, by definition, has started in another thread.
I thought that something like this might work:
setUpRun
kineticsTask.Run
while kineticsTask.state <> kineticsTask.Running
wend
while kineticsTask.state = kineticsTask.Running
wend
endRun
But, this appears to block the task from updating the user interface until the task is done, which is the problem that I was trying to solve in the first place!
Also, the data in the listbox does not seem to be available to the window in which the plot is to be made, though this may be unrelated to the use of the task.
Any help would be greatly appreciated!
Thanks,
David