- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个自定义的 NSOperation
对象,我想在它被取消时更新一些数据。
我已按照 this answer 中的说明进行操作而且我没有覆盖cancel
方法。
这是我的标题:
// MyOperation.h
@interface MyOperation : NSOperation {
}
@property (nonatomic, retain) OtherDataClass *dataClass;
@end
和实现
// MyOperation.m
@implementation MyOperation
@synthesize dataClass;
- (void)main {
if ([self isCancelled]) {
[self.dataClass setStatusCanceled];
NSLog(@"Operation cancelled");
}
// Do some work here
NSLog(@"Working... working....")
[self.dataClass setStatusFinished];
NSLog(@"Operation finished");
}
@end
我在一个队列中有几个操作。我原以为,当我在队列中调用 cancelAllOperations
时,我会在日志中看到“Operation cancelled” 文本,并在我的其他类(class)中更新状态,但它不管用。队列中的操作未调用 main
方法。
为什么会发生这种情况,我该如何解决?
我试图用这个覆盖 cancel
方法:
- (void)cancel {
[super cancel];
[self.dataClass setStatusCanceled];
NSLog(@"Operation cancelled");
}
它正在工作,但我读到不应覆盖此方法。
最佳答案
当您调用cancelAllOperations
时,已经开始的操作会将isCancelled
设置为YES
。尚未开始的操作将不会开始。
关于ios - NSOperation 访问 isCancelled in main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26627324/
我有以下示例代码: static class Program { static void Main() { var cts = new CancellationToke
我想取消异步任务并停止其后台执行,我在这个问题中找到了解决方案,: Android - Cancel AsyncTask Forcefully 但实际上,我在 asynctask 中的代码是将一些数据
我正在处理相当多的遗留 AsyncTask 代码,并且必须自己在我们的代码库中编写一些。但是,仔细阅读文档中的 cancel() 方法让我很困惑。文档说: Attempts to cancel exe
我的 doInBackground() 方法中有一个特定命令,该命令持续时间约为 20 秒。理想情况下,我可以在用户取消任务后立即中断它,但由于程序在完成之前不会通过该命令,所以无论如何它最终都会花费
我有一个应用程序,我可以在其中连接到 Web 服务以检索数据。我正在使用 AsyncTask 来执行此操作。这是我在 doInBackground 中使用的一段代码: publishProgress(
现状 我已经创建了一个自定义的 NSOperation 对象,我想在它被取消时更新一些数据。 我已按照 this answer 中的说明进行操作而且我没有覆盖cancel方法。 这是我的标题: //
我这里有一个简单的程序 private static void CancellingSingleTask() { DateTime whenStarted = DateTime.Now;
当我取消任务时,等待结果仍然为 IsCanceled 属性返回 true。似乎出了点问题。 请指教。这是代码: CancellationTokenSource _cancelLationToken =
我意识到当我使用属性 IsCancel = True 设置退出按钮时,窗口的 Closing 事件将触发两次。 private void exitButton_Click(object sen
这个问题已经有答案了: how to cancel out of operation created with addOperationWithBlock? (2 个回答) 已关闭 9 年前。 所以,
这个问题已经有答案了: Trying to stop swingworker (4 个回答) 已关闭 9 年前。 我创建了一个有 3 个按钮的 GUI;连接、断开、中止。它们都共享一个公共(publi
所以我在 SwingWorker 中有 isCancelled 的代码 boolean isCancelled() return true; 它给了我错误 attempting to assign w
我有这个异步方法: private static async Task Initializ( ) { /*Do Stuff Here*/ } 我希望能够监控调用此函数所产生的任务: Task T =
我无法弄清楚如何让用户登录我的应用程序。 [FBSDKAccessToken currentAccessToken] 为 nil,所以我调用: [[[FBSDKLoginManager alloc]
本文整理了Java中org.bukkit.event.weather.WeatherChangeEvent.isCancelled()方法的一些代码示例,展示了WeatherChangeEvent.i
我正在使用 React-native 构建一个小应用程序(我认为这不相关)。 该应用程序最终转到 Facebook 请求授权。 但是当我点击确定时,我被发送到一个 isCancelled 回调。 这是
什么时候Task.IsCanceled = true; 代码: var cts = new CancellationTokenSource(); string result = ""; cts.Can
本文整理了Java中org.apache.hadoop.hdfs.protocol.ZoneReencryptionStatus.isCanceled()方法的一些代码示例,展示了ZoneReencr
我一直在想,您能否将 cancel/cancelAllOperations/.isCancelled 与您使用 GCD 启动的线程一起使用? 目前,我只是使用一个 bool 值作为标志,以取消后台进程
如果我在与取消 token 关联的任务中调用 cancellationTokenSource.Cancel,则会正确抛出 OperationCancelledException,但是,task.IsC
我是一名优秀的程序员,十分优秀!