private async Task Sending() { try { IsSendingQueue = true; lock (SendTempQueueLock) { SendQueue.InsertRange(0, SendTempQueue); SendTempQueue.Clear(); } await SendAsync(PacketSerializer.Serialize(SendQueue, Key, Type == GSLiveType.Command)); } catch (Exception e) { e.LogException <GsTcpClient>( Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "Sending"); lock (SendTempQueueLock) { SendTempQueue.InsertRange(0, SendQueue); } } finally { IsSendingQueue = false; SendQueue.Clear(); } }
internal override void StopReceiving(bool isGraceful) { try { IsAvailable = false; IsSendingQueue = false; DataBuilder?.Clear(); SendQueue?.Clear(); lock (SendTempQueueLock) { SendTempQueue?.Clear(); } SendQueueTimer?.Stop(); SendQueueTimer?.Close(); OperationCancellationToken?.Cancel(false); OperationCancellationToken?.Dispose(); _client?.Close(); } catch (Exception) { // ignored } finally { Key = null; _client = null; _clientStream = null; OperationCancellationToken = null; DataReceived = null; RecvThread = null; SendQueueTimer = null; try { GC.SuppressFinalize(this); } catch (Exception) { // ignored } DebugUtil.LogNormal <GsTcpClient>( Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "StopReceiving", "GsTcpClient -> StopReceiving Done"); } }