StreamReader가 스레드 안전하지 않기 때문에 작동하지 않는 것 같네요. (Google은 도움이되지 않습니다. Google이 도움이되지 않습니다.)StreamReader ThreadSafe 문제? 혹시?
어쨌든 나는 정확히 무엇이 문제인지 정확하게 파악하려고 노력해 왔습니다. 이 코드는 80 %의 시간 동안 작동하고 다른 시간에는 들어오는 패킷을 구문 분석하지 못하고 그냥 삭제합니다.
이것은 http와 유사한 tcp 서버를 쓰는 경우 무효입니다. http 패킷과 똑같이 작동하지만 "CONTENT-LENGTH"헤더는 패킷 데이터 (페이로드)의 길이를 알려줍니다. 문제가 발생한 곳입니다. 누구든지이 방법을 개선하고 수정하는 방법을 제안 해 줄 수 있습니까? 왜냐하면 나는 완전히 잃어 버렸기 때문이다.
void InternalStart()
{
bool continueWhile = true;
while (continueWhile)
{
if (SR.EndOfStream)
{
continueWhile = false;
break;
}
if (par_ReadStatus != ReadStatusEnum.WaitingForPayload)
{
int charCode = SR.Peek();
if (charCode == -1)
{
continueWhile = false;
break;
}
string outputLine = "";
outputLine = SR.ReadLine();
ReadLine(outputLine);
}
else if (par_ReadStatus == ReadStatusEnum.WaitingForPayload)
{
int length = int.Parse(par_ParsingPacket.Attributes["CONTENT-LENGTH"]);
char[] array = new char[length];
for (int i = 0; i < length; i++)
{
array.SetValue(Convert.ToChar(SR.Read()), i);
}
string payload = new string(array);
ReadLine(payload);
}
}
if (ReadEnd != null)
{
ReadEnd();
}
}
발생하는 오류에 대한 자세한 정보를 제공 할 수 있습니까? –
가능한 복제본 [StreamWriter Multi Threading C#] (http://stackoverflow.com/questions/19304209/streamwriter-multi-threading-c-sharp) – Liam