Why does a TimerFcn fail to operate once another function is called?

8 ビュー (過去 30 日間)
Brandon
Brandon 2013 年 6 月 12 日
コメント済み: Walter Roberson 2017 年 1 月 16 日
I have created a timer to update a waitbar while another funciton is called to read in a data file. The purpose is to show the end user of my GUI that the process is running.
The function that reads in the data file is a mex file and I do not have the ability to update the waitbar directly from it.
I have placed a pause(10) command before the function call to the mex file and the timerfcn works great for those 10 seconds then ceases while the mex file function runs.
Any ideas or reasons why this would happen or ways to fix it would be greatly appreciated.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 12 日
Timers work at the MATLAB level. If MATLAB is not in control, such as if a mex routine has been called (and that routine does not request drawnow()) then the timers cannot work until MATLAB gains control again.
If you have the Parallel Computing Toolkit, you could have the waitbar in one thread and the call to the mex routine in another thread, and you could have the second thread notify the first thread when there was some news about the status of the second thread.
However, that arrangement would not, you will find, be of any benefit in updating the waitbar itself: as long as the mex routine is running, you cannot know how far it has proceeded, cannot know whether perhaps the mex routine got into an infinite loop or got stuck waiting for I/O or waiting for an interrupt that never arrived or got swapped out so that Windows could fly the logo around the screensaver. 15 seconds without return could mean 15 seconds of progress but it might mean no progress at all.
There is, though, a point in waiting the user to be able to cancel an active thread that might happen to be in a mex routine; there is also a point in having "watchdog times" that detect that Something Is Wrong.
The only clean way to force MATLAB activity to top that I have noticed as yet, is to use the Parallel Computing batch() facility, which has a cancel() operation (though I do not know if that can stop something that is already running.)

その他の回答 (1 件)

Jan
Jan 2013 年 6 月 13 日
編集済み: Jan 2013 年 6 月 13 日
You can trigger a drawnow from inside the MEX:
mexCallMATLAB(0, NULL, 0, NULL, "drawnow");
You can even start the update of the progressbar directly using mexCallMATLAB.
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 16 日
I was going to ask you to attach the .m and the .fig and a sample data file (if required), but looking further I can see that the code access a microsoft database; I am not sure I could run that on my Mac at all.
Walter Roberson
Walter Roberson 2017 年 1 月 16 日
It would also be a good idea to start a new Question for this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by