public bool ProcessMessage(NetworkMessage msg) { try { if (!_isRunnging) { _server.Send(_client, NetworkMessage.Create(NetworkOperation.DataAccept)); _isRunnging = true; return(true); } switch (msg.Type) { case NetworkOperation.Deny: _isRunnging = false; _toSend.Dispose(); _errorHandler(new InvalidOperationException("Operation Cancelled from Client")); return(false); case NetworkOperation.DataNext: var chunk = _getArray(); try { var count = _toSend.Read(chunk, 0, chunk.Length); if (count == 0) { _toSend.Dispose(); _server.Send(_client, NetworkMessage.Create(NetworkOperation.DataCompled)); Thread.Sleep(2000); return(false); } _server.Send(_client, NetworkMessage.Create(NetworkOperation.DataChunk, chunk, count)); return(true); } finally { _returnArray(chunk); } default: _toSend.Dispose(); return(false); } } catch (Exception e) { _toSend.Dispose(); _errorHandler(e); _server.Send(_client, NetworkMessage.Create(NetworkOperation.Deny)); return(false); } }