[英]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.