首页 \ 问答 \ iPhone - Grand Central Dispatch在iPhone 4S上无法正常工作(iPhone - Grand Central Dispatch not working correctly on iPhone 4S)

iPhone - Grand Central Dispatch在iPhone 4S上无法正常工作(iPhone - Grand Central Dispatch not working correctly on iPhone 4S)

我有这个应用程序是我的iPhone 4启动时创建的。 现在,这个应用程序没有在iPhone 4S上运行。

我已将罪魁祸首列为GCD部分。 这里是:

dispatch_group_t my_group = dispatch_group_create();

dispatch_queue_t queue1 = 
        dispatch_queue_create("Queue 1", NULL);

dispatch_queue_t queue2 = 
        dispatch_queue_create("Queue 2", NULL);


dispatch_group_async(my_group, queue1, ^{
        [self doStuff1];
});

dispatch_group_async(my_group, queue2, ^{
        [self doStuff2];
});

dispatch_group_notify(my_group, dispatch_get_main_queue(), ^{
 // this is block 3, this is to be executed after both queues end processing
 // this is never executed on iPhone 4S, but is executed on iPhone4
 // no error message, but execution never starts inside this block
});

这个想法是这样的:创建两个队列和一个组。 我使用该组以异步方式为两个队列启动任务。 当两者都完成后,该组发射另一块任务。

这项工作在iPhone 4上非常出色,但最终的第3块从未到达。

有什么理由呢? 任何线索?

谢谢。


I have this app of mine created for iPhone 4 when it was launched. Now, this app is not running on iPhone 4S.

I have identified the culprit section as a GCD part. Here it is:

dispatch_group_t my_group = dispatch_group_create();

dispatch_queue_t queue1 = 
        dispatch_queue_create("Queue 1", NULL);

dispatch_queue_t queue2 = 
        dispatch_queue_create("Queue 2", NULL);


dispatch_group_async(my_group, queue1, ^{
        [self doStuff1];
});

dispatch_group_async(my_group, queue2, ^{
        [self doStuff2];
});

dispatch_group_notify(my_group, dispatch_get_main_queue(), ^{
 // this is block 3, this is to be executed after both queues end processing
 // this is never executed on iPhone 4S, but is executed on iPhone4
 // no error message, but execution never starts inside this block
});

the idea is this: two queues are created and a group. I fire tasks for both queues, asynchronously, using the group. When both are finished, the group fires another block of tasks.

This work wonderfully on iPhone 4, but the final block 3 is never reached.

Any reason for that? Any clues?

thanks.


原文:https://stackoverflow.com/questions/8186798
更新时间:2021-09-27 16:09

最满意答案

因此,解决将N个第3行项目纳入您的课程的具体问题,您可以执行类似的操作(显然您可以进行一些更改,因此它更适合您的应用程序)。

public class MyTextFile
{
    public List<Array> Commands = new List<Array>();

    public void EnumerateCommands()
    {
        for (int i = 0; i < Commands.Count; i++)
        {
            foreach (var c in Commands[i])
                Console.Write(c + " ");
            Console.WriteLine();
        }
    }
}


class Program
{
    static void Main(string[] args)
    {
        string line = "";
        int count = 0;
        MyTextFile tf = new MyTextFile();
        using (StreamReader sr = new StreamReader(@"path"))
        {
            while ((line = sr.ReadLine()) != null)
            {
                count += 1;

                if (count >= 3)
                {
                    object[] Arguments = line.Split(',');
                    tf.Commands.Add(Arguments);
                }
            }
        }
        tf.EnumerateCommands();
        Console.ReadLine();
    }
}

至少现在你有一个'MyTextFile'类中的命令列表,你可以枚举并完成这些命令。

**我添加了EnumerateCommands方法,以便您可以实际看到列表存储行项目。 代码应该在具有适当“使用”语句的控制台应用程序中运行。

希望这可以帮助。


So, addressing the specific issue of getting N number of line 3 items into your class, you could do something like this (obviously you can make some changes so it is more specific to your application).

public class MyTextFile
{
    public List<Array> Commands = new List<Array>();

    public void EnumerateCommands()
    {
        for (int i = 0; i < Commands.Count; i++)
        {
            foreach (var c in Commands[i])
                Console.Write(c + " ");
            Console.WriteLine();
        }
    }
}


class Program
{
    static void Main(string[] args)
    {
        string line = "";
        int count = 0;
        MyTextFile tf = new MyTextFile();
        using (StreamReader sr = new StreamReader(@"path"))
        {
            while ((line = sr.ReadLine()) != null)
            {
                count += 1;

                if (count >= 3)
                {
                    object[] Arguments = line.Split(',');
                    tf.Commands.Add(Arguments);
                }
            }
        }
        tf.EnumerateCommands();
        Console.ReadLine();
    }
}

At least now you have a list of commands within your 'MyTextFile' class that you can enumerate through and do stuff with.

** I added the EnumerateCommands method so that you could actually see the list is storing the line items. The code should run in a Console application with the appropriate 'using' statements.

Hope this helps.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)