-3
我正在开发一个WPF应用程序。 在这个应用程序中,我使用Taks(线程)从多个txt文件中读取并显示它们。奇怪的错误在C#WPF
有时候我得到一个异常
目标数组不够长复制集合中的所有项目。检查数组索引和长度。
,并详细我可以读:
C:\ WINDOWS \ mscorlib.pdb:无法找到或打开PDB文件。
和:
类型“System.ArgumentException”的第一次机会异常出现在mscorlib.dll
我不知道是启动调试,在没有模式这个奇怪的例外。
更新:阅读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("");
}
发布一些代码,可以帮助... – GrandMasterFlush 2013-02-22 13:05:10
我真的想,但我不知道哪一部分张贴...的Aplication包含大量的代码... – RayOldProf 2013-02-22 13:07:43
你正在使用数组的地方^^ – 2013-02-22 13:09:49