cocoa - NSOperation子类cancel的正确编程方法

标签 cocoa concurrency

嗨 我使用 5.5 版本的 mysql 连接。版本 mysqllibclient. 如果我看到 isCancelled 开始为 yes,是否有一种方法可以停止 mysql 查询? 定时器在 nsoperation 中工作不稳定,我不知道为什么(请参阅我关于 nstimer 问题的问题,它没有得到解答)。

最佳答案

// you have two immediate options:

// 1) override cancel:
- (void)cancel {
    [super cancel];
    /* get out */
}

// 2) test isCancelled
- (void)main {
    /* ... */
    if (self.isCancelled) {
      /* get out */
    }
    else {
      /* continue working */
    }
    /* ... */
}

关于cocoa - NSOperation子类cancel的正确编程方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5345478/

相关文章:

iphone - 如何在不使我的应用程序崩溃的情况下发布此 NSXMLParser?

cocoa - Cocoa 中进程之间传递数据的最佳实践

java - Java 同步方法

haskell - 如何在 Haskell 中最好地同步游戏引擎和网络服务器?

java - 为什么我不能使用原语作为同步部分的互斥体?

java - 为什么或何时 Map.get(..) 需要同步?

java - 无锁数组元素交换

objective-c - Mac OS X : Drawing into an offscreen NSGraphicsContext using CGContextRef C functions has no effect. 为什么?

macos - 操作系统: NSButton with tag is not recognized

ios - 性能 - NSValue 中的结构与容器对象