【发布时间】:2013-08-13 03:01:31
【问题描述】:
我想知道如何从后台函数中停止另一个函数。
另外,我还要排干NSAutoreleasePool,但是不知道怎么做。
如果我不释放池,我认为这个应用程序有时会冻结。
property i : 0
property myLabel : missing value
on myStartButtonHandler_(sender)
my performSelectorInBackground_withObject_("start", missing value) -- This code prevents "Stop" Button from freezing.
end myStartButtonHandler_
on myStopButtonHandler_(sender)
-- I want to stop start() function and drain AutoreleasePool!
-- I don't want to use "quit me" because I want to stop only start() function.
end myStopButtonHandler_
on start()
repeat
set i to i + 1
myLabel's setIntegerValue_(i)
delay 1
end repeat
end start
你可以从这里下载源代码 --> https://dl.dropboxusercontent.com/u/97497395/test2.zip
供您参考,我使用的是 Xcode 4.6.3。
编辑
我的脚本有delay 300 命令,所以我无法通过检查变量的值来停止函数。对不起。
编辑
我想到了在延迟命令时停止该功能的想法。
on start()
repeat 5 times
if i = 1 then
error -128
else
delay 60
end repeat
end start
on myStopButtonHandler_(sender)
set i to 1
end myStopButtonHandler_
我可以在 60 秒内停止该功能,但我无法在按下停止按钮后立即停止。所以,我还在等你的答复。
【问题讨论】:
标签: macos nsautoreleasepool applescript-objc