-3

我正在开发一个 WPF 应用程序。在这个应用程序中,我使用 Taks(thread) 从多个 txt 文件中读取并显示它们。

有时我会遇到异常

目标数组的长度不足以复制集合中的所有项目。检查数组索引和长度。

我可以详细阅读:

C:\Windows\mscorlib.pdb:找不到或打开 PDB 文件。

和:

mscorlib.dll 中出现了“System.ArgumentException”类型的第一次机会异常

我不知道要开始调试,并且这个奇怪的异常没有模式。

更新:读取txt文件的代码:

        public void LoadCompassLogFile(String fileName) {
        //Thread.CurrentThread.Priority = ThreadPriority.Highest;
        if (!fileName.Contains("Compass")) {
            throw new FileLoadException("Wrong File");
        }

        CompassLogLoadCompleted = false;
        CompassLogLoadPercent = 0;
        _compassLogCollection.Clear();

        int numberOfSingleLineLog = 0;
        String[] lines = new string[] {};

        String temp = "";
        DateTime dateTime = new DateTime();
        LoggingLvl loggingLvl = new LoggingLvl();
        LoggingLvl.ELoggingLvl eLoggingLvl = new LoggingLvl.ELoggingLvl();
        char[] delimiters = new[] {' '};
        string threadId = "";
        string loggingMessage = "";
        int ff = 0;

        // Read the File and add it to lines string
        try {
            lines = File.ReadAllLines(fileName);
        } catch (Exception e) {
            CompassLogLoadCompleted = true;
            CoreServiceLogLoadCompleted = true;
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }

        string[] parts;

        for (int j = 0; j < lines.Count(); j++) {
            string dateAndTimestamp = "";
            if (!CompassLogLoadCompleted) {
                try {
                    lock (_myLock) {
                        parts = lines[j].Split(delimiters,
                                               StringSplitOptions.
                                                   RemoveEmptyEntries);
                    }

                    numberOfSingleLineLog++;
                    foreach (string t in parts) {
                        switch (ff) {
                            case 0:
                                dateAndTimestamp = t;
                                break;
                            case 1:
                                dateAndTimestamp += " " + t.Replace(",", ".");
                                dateTime = DateTime.Parse(dateAndTimestamp);
                                dateAndTimestamp = "";
                                break;
                            case 2:
                                eLoggingLvl = loggingLvl.ParseLoggingLvl(t);
                                break;
                            case 3:
                                threadId = t;
                                break;

                            default:
                                temp += t;
                                break;
                        }

                        ff++;
                    }

                    loggingMessage = temp;

                    temp = "";

                    ff = 0;

                    loggingLvl = new LoggingLvl(eLoggingLvl);

                    CompassLogData cLD = new CompassLogData(
                        numberOfSingleLineLog,
                        dateTime,
                        loggingLvl, threadId,
                        loggingMessage);

                    _compassLogCollection.Add(cLD);

                    //loggingMessage = "";
                } catch (Exception ex) {
                    Console.Out.WriteLine("Shit Happens");
                    Console.Out.WriteLine(ex.StackTrace);
                }
                CompassLogLoadPercent = ((double) j
                                         /lines.Count())*100;
            }
        }

        CompassLogLoadCompleted = true;
        Console.Out.WriteLine("Compass LOADING DONE");

        Console.Out.WriteLine("numberOfSingleLineLog: " +
                              numberOfSingleLineLog);
        Console.Out.WriteLine("");
    }
4

1 回答 1

0

我认为 .net 中数组的长度最大为 2GB,因此根据您放入的类型,您需要将 (2^31)/8 划分为 long[] 和一个字节,我认为它是 (2^31 )/4 大约 500 MB。你的文件比那个大吗?

对于第二个找不到 PDB 的问题,请转到工具 --> 选项 --> 调试 --> 符号并选择 Microsoft 符号服务器,这可以解决问题。

如果您有足够的信息,这也可以解决您的最后一个问题......

于 2013-02-22T13:15:43.827 回答