[英]C# List<string> in linux with Mono
I have an executable file that processes a large number (1000+) of strings and adds each one to a List of strings.我有一个可执行文件,它处理大量(1000+)个字符串并将每个字符串添加到字符串列表中。 It is coded in C#, compiled in Visual Studio 2017 on a windows machine, then exported to and run on a Linux machine with Mono.它用 C# 编码,在 Windows 机器上的 Visual Studio 2017 中编译,然后导出到带有 Mono 的 Linux 机器上并运行。 Oddly enough, writing all of the strings to a text file works just fine, but adding them to the list causes the program's user interface to freeze and become unresponsive.奇怪的是,将所有字符串写入文本文件的工作正常,但将它们添加到列表会导致程序的用户界面冻结并无响应。
Here's my code:这是我的代码:
client.BigDB.LoadRange("Clans", "ByName", null, startAt + "0000000000", stopAt + "zzzzzzzzzz", 1000, delegate (DatabaseObject[] o)
{
foreach (DatabaseObject obj in o)
{
//this section here does not work as intended
//string ClanName = obj.GetString("name");
//ClanNames.Add(ClanName);
//main.ui.AppendTestBox(ClanName);
//Clans++;
//but this section works perfectly
using (StreamWriter w = File.AppendText("ClanNameList.txt"))
{
w.Write(obj.GetString("name") + Environment.NewLine);
}
}
});
After inspecting the output file, I suspect that it is getting caught on the following string: "AK Union, Local 47".检查输出文件后,我怀疑它被以下字符串捕获:“AK Union, Local 47”。 It processed every previous kind of character without problems, but it appears to not like commas for some reason.它可以毫无问题地处理以前的每种字符,但由于某种原因,它似乎不喜欢逗号。 How do I get around this, if that's actually what's going on?我该如何解决这个问题,如果这确实是发生了什么?
I did try to search for this problem on google and this site, but the search results are wildly unhelpful and quite unrelated to what I need :(我确实尝试在谷歌和这个网站上搜索这个问题,但搜索结果非常无用,而且与我需要的完全无关:(
I cant see exactly your problem, though one thing i would suggest is update once via a StringBuilder
, not 1000 times我无法确切地看到您的问题,尽管我建议的一件事是通过StringBuilder
更新一次,而不是 1000 次
client.BigDB.LoadRange("Clans", "ByName", null, startAt + "0000000000", stopAt + "zzzzzzzzzz", 1000, delegate (DatabaseObject[] o)
{
var sb = new StringBuilder();
foreach (DatabaseObject obj in o)
{
var name = obj.GetString("name");
ClanNames.Add(name);
sb.Append(name);
}
main.ui.AppendTestBox(sb.ToString());
});
StringBuilder.Append Method (System.Text) StringBuilder.Append 方法 (System.Text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.