-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