我在分配CreatePostTranslationsTable
来阅读文件时有StackOverflowException
,我不知道为什么会这样:(
以下是例外情况:
StreamReader
以下是代码:
$exception {"Exception of type 'System.StackOverflowException' was thrown."} System.StackOverflowException
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HResult -2147023895 int
HelpLink null string
+ InnerException null System.Exception
Message "Exception of type 'System.StackOverflowException' was thrown." string
Source null string
StackTrace null string
TargetSite null System.Reflection.MethodBase
+ Static members
+ Non-Public members
答案 0 :(得分:0)
我不知道这是否与您的问题有关,但是对int
使用静态变量意味着如果2个线程同时调用StreamReader
,则可能会出现问题。< / p>
另外,CompileAndRun
imlements StreamReader
,因此您应该在其上调用IDisposable
或使用Dispose
这样的块:
using
另外,不应该这一行:
class Compile_Import
{
public static string getargs = null;
public static void CompileAndRun(FileInfo importInfo, string args)
{
getargs = args;
if(importInfo.Extension == ".cbe" && importInfo.Exists)
{
using (StreamReader sr = new StreamReader(importInfo.FullName)) //Where my problem occurs.
{
string curlinecont = null;
while((curlinecont = sr.ReadLine()) != null)
{
string RawToken =
Parser.Parse.ParseLineIntoToken(Run.Stats.CurrentLineContents);
Token_Management.Process_Token.ActOnToken(RawToken);
}
}
}
}
是:
string RawToken =
Parser.Parse.ParseLineIntoToken(Run.Stats.CurrentLineContents);
?否则,您没有使用从文件中读取的行,因此它使得读取文件毫无意义。