This commit is contained in:
BruceChen 2022-09-03 02:06:16 +08:00
parent 0382e07d50
commit 3b95cbcce0

View file

@ -195,30 +195,25 @@ namespace MinecraftClient.Protocol.Handlers
cancelToken.ThrowIfCancellationRequested(); cancelToken.ThrowIfCancellationRequested();
handler.OnUpdate(); handler.OnUpdate();
stopWatch.Restart();
stopWatch.Start();
while (packetQueue.TryTake(out Tuple<int, Queue<byte>>? packetInfo)) while (packetQueue.TryTake(out Tuple<int, Queue<byte>>? packetInfo))
{ {
(int packetID, Queue<byte> packetData) = packetInfo; (int packetID, Queue<byte> packetData) = packetInfo;
HandlePacket(packetID, packetData); HandlePacket(packetID, packetData);
stopWatch.Stop();
if (stopWatch.Elapsed.Milliseconds >= 100) if (stopWatch.Elapsed.Milliseconds >= 100)
{ {
stopWatch.Reset();
handler.OnUpdate(); handler.OnUpdate();
stopWatch.Restart();
} }
stopWatch.Start();
} }
stopWatch.Stop();
if (stopWatch.Elapsed.Milliseconds < 100) int sleepLength = 100 - stopWatch.Elapsed.Milliseconds;
Thread.Sleep(100 - stopWatch.Elapsed.Milliseconds); if (sleepLength > 0)
stopWatch.Reset(); Thread.Sleep(sleepLength);
} }
} }
catch (System.IO.IOException) { }
catch (SocketException) { }
catch (ObjectDisposedException) { } catch (ObjectDisposedException) { }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }