Will wait for all data to be sent before closing.
public Task CloseAsync() { _socket.Shutdown(SocketShutdown.Send); var t = _closeEvent.WaitAsync(5000); // release again so that we can take reuse it internally t.ContinueWith(x => { _closeEvent.Release(); IsConnected = false; }); return t; }