I am intending to make the NSOperationQueue serial instead of concurrent.
我打算将NSOperationQueue串行而不是并发。
One way I know is:
我知道的一种方法是:
NSOperationQueue *globalQueue;
globalQueue.maxConcurrentOperationCount =1;
Is there any other way?
还有别的办法吗?
1 个解决方案
#1
13
If you want a serial queue, you are right setting maxConcurrentOperation to one. You can also use [NSOperationQueue mainQueue] instead of creating a new queue, and so queue operations on the main thread. But that is only useful if very short operations are added and so the user interface is not blocked. And on the other hand you have not to worry about threads n synch.
如果需要串行队列,则将maxConcurrentOperation设置为1。您也可以使用[NSOperationQueue mainQueue]而不是创建新队列,从而对主线程进行队列操作。但这仅在添加非常短的操作时才有用,因此不会阻止用户界面。而另一方面,你不必担心线程n同步。
You can add operations to any queue with addOperations:waitUntilFinished:YES or sending the message waitUntilAllOperationsAreFinished every time you add an operation. That way you are serializing operations instead of defining the queue as serial.
您可以使用addOperations向任何队列添加操作:waitUntilFinished:YES或每次添加操作时发送消息waitUntilAllOperationsAreFinished。这样您就可以序列化操作,而不是将队列定义为串行。
#1
13
If you want a serial queue, you are right setting maxConcurrentOperation to one. You can also use [NSOperationQueue mainQueue] instead of creating a new queue, and so queue operations on the main thread. But that is only useful if very short operations are added and so the user interface is not blocked. And on the other hand you have not to worry about threads n synch.
如果需要串行队列,则将maxConcurrentOperation设置为1。您也可以使用[NSOperationQueue mainQueue]而不是创建新队列,从而对主线程进行队列操作。但这仅在添加非常短的操作时才有用,因此不会阻止用户界面。而另一方面,你不必担心线程n同步。
You can add operations to any queue with addOperations:waitUntilFinished:YES or sending the message waitUntilAllOperationsAreFinished every time you add an operation. That way you are serializing operations instead of defining the queue as serial.
您可以使用addOperations向任何队列添加操作:waitUntilFinished:YES或每次添加操作时发送消息waitUntilAllOperationsAreFinished。这样您就可以序列化操作,而不是将队列定义为串行。