private static async Task <WebSocketConnectionSummary> RunReceiveTest(Func <IWritableChannel, CancellationToken, Task> producer) { using (var factory = new ChannelFactory()) { var outbound = factory.CreateChannel(); var inbound = factory.CreateChannel(); var timeoutToken = TestUtil.CreateTimeoutToken(); var producerTask = Task.Run(async() => { await producer(inbound, timeoutToken).OrTimeout(); inbound.CompleteWriter(); }, timeoutToken); var consumerTask = Task.Run(async() => { var connection = new WebSocketConnection(inbound, outbound, options: new WebSocketOptions().WithAllFramesPassedThrough()); using (timeoutToken.Register(() => connection.Dispose())) using (connection) { // Receive frames until we're closed return(await connection.ExecuteAndCaptureFramesAsync().OrTimeout()); } }, timeoutToken); await Task.WhenAll(producerTask, consumerTask); return(consumerTask.Result); } }
/// <summary> /// Disposes the connection and stops the gesture server. /// </summary> public void Stop() { if (connection != null) { connection.Dispose(); } server.Stop(); }
private void DisposeInternal() { try { SendDataInternal(new Dictionary <string, object> { { "type", "shutdown" } }); Thread.Sleep(1000); connection.Dispose(); } catch { } }
public void Dispose() => _webSocket.Dispose();
public void Dispose() { WebSocketConnection?.Dispose(); NewMessageEvent?.Dispose(); }