GUI program with parfeval
4 ビュー (過去 30 日間)
古いコメントを表示
HILTON MARQUES SANTANA
2022 年 7 月 20 日
コメント済み: HILTON MARQUES SANTANA
2022 年 7 月 21 日
Hello Matlab community, I'm enhancing a GUI program with mouse events and simultaneously accessing an online database. My idea to avoid GUI hangs while querying the database is as follows:
thread_ptr = parfeval(@(c, varargin) fetch(c.Value, varargin{:}), 1, c, query);
pause(3) % not stop mouse events during query
data = fetchOutputs(thread_ptr);
This code seems to work, but I want some pause() function that stops when parfeval stops running. I have already tried wait() , but apparentelly wait() also seems to stop the GUI. Any ideas?
0 件のコメント
採用された回答
Edric Ellis
2022 年 7 月 21 日
編集済み: Edric Ellis
2022 年 7 月 21 日
You should be able to cause the GUI to update by using wait in a loop, together with drawnow. A bit like this:
while ~wait(thread_ptr, 'finished', 0.1) % wait for 0.1 seconds
drawnow % update the UI if the future wasn't finished
end
A slightly different approach might actually work better here. You can use afterEach with parfeval to automatically run a function when your evaluation on the worker completes. (More details on this page). Something a bit like this
thread_ptr = parfeval(..);
afterEach(thread_ptr, @(result) doStuffWithResult(result), 0)
In this way, doStuffWithResult automatically gets called with the outputs from thread_ptr as soon as they are available.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Asynchronous Parallel Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!