喂,
在我的项目中,我使用Antlr.StringTemplate.StringTemplateGroup类来创建本地化模板。我访问.st文件并按如下所示设置所需的属性。
public StringTemplate WrapValuesReportTemplateContent(
private StringTemplateGroup StringTemplateGroup = new StringTemplateGroup(StringTemplateGroupName);
StringTemplate stringTemplate = this.StringTemplateGroup.GetInstanceOf(path);
stringTemplate.SetAttribute("atr1", value1);
stringTemplate.SetAttribute("atr2", value2);
return stringTemplate
)管理器重复使用该类,因此触发了以下异常。
System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithread applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
at Antlr.StringTemplate.ConsoleErrorListener.Error(String s, Exception e)
at Antlr.StringTemplate.StringTemplate.BreakTemplateIntoChunks()我是StringTemplate的新手,我不清楚StringTemplates到底是如何工作的。从错误描述中,我了解到.st资源没有关闭。我有以下问题:
任何澄清都是非常有用的。谢谢
发布于 2015-08-19 14:47:36
我最近遇到了同样的错误!看看您的堆栈跟踪:它是从ConsoleErrorListener抛出的。简而言之,抛出异常是因为两个线程试图写入Console.Out流。若要消除此错误,应重写模板的错误处理程序。
标记为答案的解决方案将有效,但会出现太多的锁争用。
https://stackoverflow.com/questions/29099980
复制相似问题