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
最满意答案
因此,解决将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.
相关问答
更多-
使用File.Create(textfilename).Close(); 正如错误消息所示 Use File.Create(textfilename).Close(); As the error message suggests
-
您需要调用StreamWriter.Flush或将StreamWriter.AutoFlush设置为true。 也就是说,如果你使用statment,一切都应该正常工作。 using(StreamWriter sw = new StreamWriter(fs)) { ArrayList chartList = GetChart(maintNode); foreach (var line in chartList) { sw.WriteLine(line); ...
-
我能想到的最简单的方法是使用Xaml实际保存数据。 这是一个合适的解决方案,因为您已经在使用WPF。 简单的例子: List
- > items1 = new List
- >();
// ... add items...
XamlServices.Save(@"c:\path\to\file.xaml", items1);
然后加载: var items2 = XamlServices.Load(@"c:\path\to\file.xaml");
请注意 ...
-
C#替换文本文件中的路径(C# Replacing path in Text File)[2021-10-14]
这就是你如何使用它。 在这种情况下,您不需要使用RegEx,因为要替换的字符串定义良好: File.WriteAllText(@"C:\Folder\Files\print.txt", File.ReadAllText(@"C:\Folder\Files\print.txt").Replace(@"C:\folder\files\", "Copy ")); This is how you can use it. You do not need to use RegEx in this case, beca ... -
一种简单易用的写入文件的方法是File.WriteAllText(filePath,p.ToString())。 您还必须在类Person中覆盖方法ToString,因此您可以将要保存的信息返回到文件,否则它将默认情况下将类的名称返回为字符串。 如果你需要一种最出色的方式,你应该使用StreamWriter。 A simple and easy to use method for writing into a file is File.WriteAllText( filePath, p.ToString() ...
-
在C#文本文件中创建不重复的字符串条目列表(Creating a list of no duplicate string entries in a text file at C#)[2022-12-04]
如果是“不重复”,请查看HashSet; 您可能会发现TextWriter和TextReader太复杂 - File.AppendAllLines改为使用File.ReadLines() , File.AppendAllLines : static void Main(string[] args) { // better practice is paths combining string path = Path.Combine(Environment.Speci ... -
使用C#将未知数量的数据从文本文件放入数组/列表(putting unknown number of data from a text file into array/list using C#)[2021-11-11]
我会说你最好的选择是像这样的Dictionary Dictionary> Key是机场名称, Value是机场跑道的集合 I would say that your best bet is a Dictionary like this Dictionary > Where the Key is the airport name and the Value is a collection of the runways tha ... -
我认为您的list已包含一些数据,您应该在向其添加新文件数据之前将其清除。 OpenFileDialog txtopen = new OpenFileDialog(); if (txtopen.ShowDialog() == DialogResult.OK) { list.Clear(); // <-- clear here string FileName = txtopen.FileName; string line; System.IO.StreamReader f ...
-
因此,解决将N个第3行项目纳入您的课程的具体问题,您可以执行类似的操作(显然您可以进行一些更改,因此它更适合您的应用程序)。 public class MyTextFile { public List
Commands = new List (); public void EnumerateCommands() { for (int i = 0; i < Commands.Count; i++) { ... -
输入示例 Root|A Root|B|C Root|B|D Root|E 你的代码的问题是你只处理TreeNodes[0]元素。 处理需要循环的元素集合 public MainWindowVM() { private ObservableCollection
mRootNodes; public IEnumerable RootNodes { get { return mRootNodes; } } string[] lines = null; ...