private void Initialize(Configuration configuration) { if (Interlocked.Equals(this.Stopped, 1)) { return; } this.OnRejected = configuration.OnRejected; this.Thread = new Thread(() => { while (true) { try { Action action = null; InternalExceptionHandler.Rethrow(InternalExceptionCode.ActionQueueTryTake, () => this.Queue.TryTake(out action)); if (action == AbortCommand) { return; } action?.Invoke(); } catch (Exception exception) { configuration.ExceptionHandler?.Invoke(exception); } } }); this.Thread.Priority = configuration.Priority; this.Thread.Start(); }
private Task SendAsyncImplementation(byte[] buffer) { if (!this.isOpen) { return(Task.Run(() => { })); } return(Task.Run(() => { lock (this.sendLock) { this.currentSend.Wait(); this.currentSend = new Task(() => InternalExceptionHandler.Try(() => this.socket.SendAsync(new ArraySegment <byte>(buffer), WebSocketMessageType.Binary, this.socketResult.EndOfMessage, CancellationToken.None).Wait())); } })); }