필터 지우기
필터 지우기

Stop an app designer callback thread like the debugger does?

조회 수: 8 (최근 30일)
Ken
Ken 2024년 4월 21일
댓글: Walter Roberson 2024년 4월 23일
It is evident that whenever the user clicks a button in an app designer app, the callback is called in a new thread. The debugger takes advantage of this, the red "stop" square button obviously terminates the currently running callback thread. Very clean, very effective.
Now, is there any way that I as a programmer can do the same thing? Here's my problem. I'm building a scientific analysis program, and the users have a lot of options. The wrong options combined with the wrong data can produce a VERY long-running computation, and the user has no good way of getting out of it. Indeed, my users are tending to click extra buttons, setting yet more computations in motion, and it ends up in a meltdown.
So, can I kill the thread, or do I just have to put checkpoints in all my long-running code and check for a stop variable?

답변 (1개)

Walter Roberson
Walter Roberson 2024년 4월 21일
"It is evident that whenever the user clicks a button in an app designer app, the callback is called in a new thread."
No, the current thread is interrupted, pushing the location onto the stack, and the callback is run in the same thread. At the end of execution of the callback, the old information is popped and execution is resumed.
The entire execution is on a single thread, unless background pool is used or unless one of the facilities of the Parallel Computing Toolbox are used. (Well, graphics runs on a seperate thread.)
(The single thread used is distinct from threads that manage the user interface.)
  댓글 수: 8
Andres
Andres 2024년 4월 23일
Okay, but hitting "the red 'stop' square button", as the OP suggests, would have similar limitations (at least), wouldn't it?
Walter Roberson
Walter Roberson 2024년 4월 23일
Yes, hitting the Stop button has the limitation that it does not stop until the next line of MATLAB code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by