标签: background-thread

IOS后台工作

我有iPhone的iPhone应用程序.我的应用程序必须连接我的服务器并定期每两个小时读取所有消息.我有一个线程来读取所有消息,但是当应用程序终止时,线程无法工作.线程是否可以独立于主代理运行,或者如何找到此问题的解决方案?

iphone multithreading background-process ios background-thread

4
推荐指数
1
解决办法
700
查看次数

魔法记录 - 在主线程块ui中获取,在后台返回nil

我是魔法记录的新手,但已经在stackoverflow上看到了一些问题,但无法找到我的问题的答案.

我必须使用这种类型的结构找到带有谓词的项:

NSArray *result = [MOSomeItems MR_findAllWithPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

在主线程结果返回一些值,但UI是冻结.

使用此构造时,结果返回nil值:

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSArray *result = [MOSomeItems MR_findAllWithPredicate:predicate];
});
Run Code Online (Sandbox Code Playgroud)

在后台获取数据的最佳做法是什么?

core-data freeze ios background-thread magicalrecord

4
推荐指数
1
解决办法
3926
查看次数

如果在ThreadPool的线程正在写文件时关闭应用程序会发生什么?

假设您使用a ThreadPool执行某些操作并假设每个操作都写入文件.所有线程ThreadPool都是后台线程,因此在关闭应用程序时它们将被终止.如果在ThreadPool将文件写入磁盘的情况下关闭应用程序会发生什么?

.net c# multithreading threadpool background-thread

4
推荐指数
1
解决办法
873
查看次数

Kotlin:如何在不冻结UI的情况下延迟Android中的代码

我正在尝试延迟我尝试过的Kotlin中的代码

Thread.sleep(1000)
Run Code Online (Sandbox Code Playgroud)

但是它冻结了UI。

有人知道为什么会这样吗,以及如何在不冻结UI的情况下进行延迟?

ui-thread background-thread kotlin

4
推荐指数
3
解决办法
4470
查看次数

iOS4创建后台计时器

我(基本上)需要在iOS 4上创建一个后台计时器,这将允许我在经过特定时间后执行一些代码.我已经读过你可以用一些来完成这个[NSThread detachNewThreadSelector: toTarget: withObject:];但是在实践中它是如何工作的?如何确保线程也保留在后台.本地通知将为我工作,因为我需要执行代码,不通知用户.

帮助将不胜感激!

objective-c ios4 localnotification background-thread

3
推荐指数
1
解决办法
1万
查看次数

当我将数据上传到 firebase 时,为什么我的应用程序冻结?

更新: ****小编辑,我发现实际上唯一冻结的是从 firebase 检索数据,尤其是需要检索的图像。func initOberserver 用于从 firebase 检索数据。所以这需要每次在后台完成。但是 tableview 必须同时可用? ****

我在后台线程上有点挣扎。我正在制作一个 firebase 应用程序,但是当我将某些内容上传到 firebase 并将其检索回应用程序时,我的应用程序冻结了一段时间。

我在一个单独的打开文件中有 2 个常量:

let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
Run Code Online (Sandbox Code Playgroud)

我有一个视图控制器:ListVC,它使用此功能从 firebase 检索数据。

func initObservers() {

    //LoadingOverlay.shared.showOverlay(self.view)
    dispatch_async(backgroundQueue, {
        DataService.ds.REF_LISTS.observeEventType(.Value, withBlock: { snapshot in
            print(snapshot.value)

            self.lists = []

            if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {

                for snap in snapshots {
                    print("SNAP: \(snap)")

                    if let listDict = snap.value as? Dictionary<String, AnyObject> {
                        let key = snap.key
                        let list = List(listKey: key, dictionary: …
Run Code Online (Sandbox Code Playgroud)

grand-central-dispatch ios background-thread firebase swift

2
推荐指数
1
解决办法
2108
查看次数

主线程完成后子线程不工作

我正在开发一个应用程序,它从不同的线程监听队列,但我有一个关于线程管理的问题。我从主应用程序启动了一个后台线程。它工作正常,但主应用程序完成后,子线程就会终止。主应用程序完成后是否有继续子线程。

我开始像下面这样的线程。

Thread myNewThread = new Thread(() => Executer.ProcessQueueMessages());
myNewThread.IsBackground = true;
myNewThread.Start();
Run Code Online (Sandbox Code Playgroud)

c# multithreading background-thread

2
推荐指数
1
解决办法
3871
查看次数

更新UI Dispatch_Async后台下载Swift

我正在使用文件夹/文件应用程序,用户可以在其中将文件下载到本地磁盘。每当用户下载文件时,我都想显示一个显示进度的下载栏。

为此,我创建了一个协议,该协议允许我的下载类和视图控制器进行通信:

协议:

protocol DownloadResponder : class {
    func downloadFinished()
    func downloadProgress(current:Int64, total:Int64)
}
Run Code Online (Sandbox Code Playgroud)

下载类:

class fileDownloader: NSObject, NSURLSessionDelegate, NSURLSessionDownloadDelegate {

    //responder
    var responder : MyAwesomeDownloadResponder?

    init(responder : MyAwesomeDownloadResponder) {
        self.responder = responder
    }

    ...

    func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {

        println("downloaded \(100*totalBytesWritten/totalBytesExpectedToWrite)")
        responder?.downloadProgress(totalBytesWritten, total: totalBytesExpectedToWrite)

    }

...

}
Run Code Online (Sandbox Code Playgroud)

然后在我的视图控制器中,我有一个触发downloadProgress功能的下载按钮:

func downloadProgress(current:Int64, total:Int64) {
        let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
        dispatch_async(dispatch_get_global_queue(priority, 0)) {
            // do some task
            var currentProgress = 100 * current …
Run Code Online (Sandbox Code Playgroud)

user-interface ios background-thread dispatch-async swift

1
推荐指数
1
解决办法
2511
查看次数

如何在后台线程上每秒执行一个方法,以免影响应用程序的性能

我试图每 30 秒访问一次我的数据库,但是,每当该方法执行时,我都可以清楚地看到应用程序的性能下降。

到目前为止,这是我当前的代码:

var timer = Timer()

override func viewDidLoad() {
    super.viewDidLoad()
    scheduledTimerWithTimeInterval()

}

func scheduledTimerWithTimeInterval(){
    timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true)
}

@objc func updateCounting(){
    getDatabaseInfo()
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试做同样的事情,但我想在后台线程上执行 getDatabaseInfo() 方法,这样应用程序的性能就不会受到影响。

timer background-thread swift

1
推荐指数
2
解决办法
2886
查看次数