Hallo,
ich habe das Problem, dass beim Ausführen meines Programms nach einer gewissen Zeit eine StackOverflowException auftritt:
An unhandled exception of type 'System.StackOverflowException' occurred in DA.exe
Eine Endlosleife hab ich keine eingebaut. Der Code funktioniert bis zu, Überlauf korrekt. Was ich mache: ich öffne eine txt-Datei mit einem StreamReader und durchsuche sie nach bestimmten Strings. Dazu verwende ich fünf verschiedenen Funktionen. Die alle etwa in so aussehen:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
| using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Globalization;
namespace DA { public static class ProcessTwo { #region Fields private static StreamReader _streamReader; private static string _line; private static string _pattern; private static string _timestampLine; private static double _timestamp; private static string _helper; private static int _currentLine; #endregion
#region Methodes public static void Activate(StreamReader streamReader, int lineNum, CultureInfo cultureInfo) { _streamReader = streamReader; _currentLine = lineNum;
_pattern = "#5"; while (!_streamReader.EndOfStream) { _currentLine++; _line = _streamReader.ReadLine(); if (_line.Contains("Ref-Time")) _timestampLine = _line; if (_line.Contains(_pattern)) { _helper = _timestampLine.Replace("Ref-Time: ", ""); _helper = _helper.Replace(" us", ""); _timestamp = System.Convert.ToDouble(_helper, cultureInfo); _helper = null; ValueContainer.SetCurrentFunctionRangeExit(_timestamp); Console.WriteLine(_currentLine); ProcessThree.Activate(_streamReader, _currentLine, cultureInfo); } } Console.WriteLine("Ende"); } #endregion } } |
diese Funktionen rufen sich gegenseitig auf und durchsuchen ein ca. 85000 Zeilen langes File. Ca. 22000 Zeilen lang geht das gut. Danach kommt der Overflow. Meine Frage ist nun, warum das geschieht? Und wie ich das verhindern kann.
Moderiert von
Christian S.: C#-Tags hinzugefügt