我现在正在使用 evernote api 在 iOS 上开发一个应用程序。我有一些关于多线程的问题。下面是我的应用程序中的多线程机制,是好是坏?欢迎任何建议。
- 使用 MainThread(Thread a) 显示和刷新 UI。
- 当用户在noteList页面时,使用线程b从evernote下载noteList。
- 当用户在noteDetail页面时,使用线程c从evernote下载noteResource。
如果用户在线程 b 未完成时单击注释列表页面中的一个注释。在使用线程c下载noteResource之前我应该取消线程b吗?或者一次运行线程 b 和线程 c 是否安全?
有关于这方面的任何文件或学费吗?
我在下面添加了代码,对吗?当用户首次登录时,masterSync 将运行,笔记标题将下载并显示。在此之后,如果用户按下同步按钮,masterSync 将再次运行,但现在它在 noteStore alloc/init 时访问 authResult 的 authenticationToken 时崩溃,我在用户登录成功时保存了 authResult,对吗?
-(void)sync:(id)obj {
NSOperationQueue *operationQueue = [AppDelegate sharedOperationQueue];
if ([obj isKindOfClass:[Note class]]) {
self.detailSync = [[[EvernoteDetailSync alloc] initWithNote:obj] autorelease];
detailSync.noteStore =[[[EvernoteNoteStore alloc] initWithToken:[authResult authenticationToken] shardId:[[authResult user] shardId]] autorelease];
[operationQueue addOperation:detailSync];
} else {
self.masterSync = [[[EvernoteMasterSync alloc] initWithNotebookGuid:obj] autorelease];
masterSync.noteStore =[[[EvernoteNoteStore alloc] initWithToken:[authResult authenticationToken] shardId:[[authResult user] shardId]] autorelease];
[operationQueue addOperation:masterSync];
}
}