简体   繁体   中英

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. 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. 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". 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

    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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM