简体   繁体   English

StringBuilder.ToString()抛出'索引超出范围'异常

[英]StringBuilder.ToString() throw an 'Index out of range' Exception

I would really appreciate someone help me resolving the following issue: 我真的很感谢有人帮我解决以下问题:

I am getting now and then the following exception: 我现在得到以下异常:

Index was out of range. 指数超出范围。 Must be non-negative and less than the size of the collection. 必须是非负数且小于集合的大小。 Parameter name: chunkLength 参数名称:chunkLength

on stringBuilder.ToString() . stringBuilder.ToString()

What is strange is if I put stringBuilder.ToString() in the watch, it works perfectly. 奇怪的是,如果我将stringBuilder.ToString()放在手表中,它stringBuilder.ToString()完美运行。

Look like it is a multi thread issue. 看起来这是一个多线程问题。 I locked the thread to prevent multi access to the stringBuilder at the same time. 我锁定了线程以防止同时多次访问stringBuilder。

public void AddString(string s)
{
  lock(this.LockObject)
  {
     StringBuilder.AppendLine(s);
  }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 StringBuilder.ToString() 抛出 OutOfMemoryException - StringBuilder.ToString() throws OutOfMemoryException StringBuilder.ToString() 读取 145M 文件时内存不足 - StringBuilder.ToString() throwing out of memory reading 145M file C#列表框无法读取StringBuilder.ToString() - C# Listbox cant read StringBuilder.ToString() Unity StringBuilder.ToString() 会导致堆内存分配吗? - Unity Does StringBuilder.ToString() cause the heap memory allocating? 为什么WPF Presentation库在StringBuilder.ToString()中包装字符串? - Why does the WPF Presentation library wrap strings in StringBuilder.ToString()? ---- s在StringBuilder.ToString()上下文中是什么意思? - What does ----s mean in the context of StringBuilder.ToString()? 隐式和显式 StringBuilder.ToString() 方法调用之间有什么区别? - What is the difference between implicit and explicit StringBuilder.ToString() method calls? StringBuilder.ToString()在字符串的开头和结尾添加“ \\”字符 - StringBuilder.ToString() is adding '\' characters in the beginning and ending of the string Stringbuilder.ToString()在javascript中转换“和”符号生成“和” - Stringbuilder.ToString() Converting " and ' symbol generate ' and " in javascript C#.NET如何不使用StringBuilder.ToString()将StringBuilder转换为Byte数组 - C# .NET How to convert StringBuilder to Byte array without using StringBuilder.ToString()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM