简体   繁体   English

如何知道当前正在运行的线程并停止它

[英]how to know the current running thread and stop it iOS

One of my IBActions are currently running, when I choose another action I want to stop my previous IBActions. 我的一个IBAction当前正在运行,当我选择另一个动作时,我想停止以前的IBAction。

I don't have any idea about how to do this. 我对如何执行此操作一无所知。

Can any one of you please help me on this. 你们中的任何一个可以帮助我吗?

Thanks in advance... 提前致谢...

You may use boolean, something like a semaphore. 您可以使用布尔值,例如信号量。 When run IBA-2, set it to true. 运行IBA-2时,将其设置为true。 IBA-1 must check it in cycle, loop or timer proc, and if it's true, set it to false and return. IBA-1必须在循环,循环或计时器proc中对其进行检查,如果为true,则将其设置为false并返回。

IBActions (if you use them as event handlers for XIB based views) are performed in main thread, if you don't create another queue or thread explicitly. IBAction(如果您将它们用作基于XIB的视图的事件处理程序)在未显式创建另一个队列或线程的情况下在主线程中执行。 You can't stop main thread, otherwise you will stop whole app. 您无法停止主线程,否则将停止整个应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM