C# 接收异步后如何处理数据

C# 接收异步后如何处理数据,c#,websocket,buffer,C#,Websocket,Buffer,目前我正在做: WebSocketReceiveResult result = await Conn.ReceiveAsync(readBuffer, token); for (int i = 1; i <= result.Count; i++) { if (CurrentPosition+i > ProcessedPosition) { Console.ForegroundColor = ConsoleColor.Blue; } el

目前我正在做:

WebSocketReceiveResult result = await Conn.ReceiveAsync(readBuffer, token);
for (int i = 1; i <= result.Count; i++)
{
    if (CurrentPosition+i > ProcessedPosition)
    {
        Console.ForegroundColor = ConsoleColor.Blue;
    }
    else
    {
        Console.ForegroundColor = ConsoleColor.Cyan;
    }
    Console.Write(readBuffer.Array[CurrentPosition+i]);
    Console.ResetColor();
}
CurrentPosition += result.Count;
WebSocketReceiveResult结果=await Conn.ReceiveAsync(读取缓冲区,令牌);
对于(int i=1;i ProcessedPosition)
{
Console.ForegroundColor=ConsoleColor.Blue;
}
其他的
{
Console.ForegroundColor=ConsoleColor.Cyan;
}
Write(readBuffer.Array[CurrentPosition+i]);
Console.ResetColor();
}
CurrentPosition+=结果计数;

我是否在缓冲区中选择了正确的位置?如何逐字节分析它?

根据您发布的内容无法判断。什么是
CurrentPosition
?为什么要将循环字符串设置为1而不是0?您要求它填写
readBuffer
为什么不直接从
readBuffer
的开头读取?CurrentPosition是当前位置,从0开始,因为WebSocketReceiveResult count表示接收的字节数,我想我必须将I设置为从1开始,以count结束。整个过程都在一个do-while循环中,ReceiveAsync连续接收实时数据,因此我需要实时处理它。我不知道您如何读取第一个字节(字节0)。