public async Task Should_only_release_once_when_entry_is_enqueued() { _sut.MaxFileSize = 1; ThreadPool.QueueUserWorkItem(x => { Thread.Sleep(100); _sut.Enqueue("Hello world").Wait(); }); await _sut.Open(); var t1 = _sut.Dequeue(TimeSpan.FromSeconds(1)); var t2 = _sut.Dequeue(TimeSpan.FromSeconds(1)); var t = await Task.WhenAll(t1, t2); t1.Result.Message.Should().Be("Hello world"); t2.Result.Should().BeNull(); }
void UpdateFileQueue() { if (MaxFileQty > 0) { int qty = FileQueue.Count - MaxFileQty + 1; if (qty > 0) { for (int i = 0; i < qty; i++) { File.Delete(FileQueue.Dequeue()); } } } }
private async Task DeliverQueuedMessages() { while (true) { try { await _tcpClient.EnsureConnected(); } catch (SocketException) { await Task.Delay(5000); continue; } _pendingMessage = await _fileQueue.Dequeue(TimeSpan.FromSeconds(10)); if (_pendingMessage == null) { continue; } try { var transportMessage = new TransportMessage(_pendingMessage.Message); _pendingMessageId = transportMessage.Id; await _tcpClient.SendAsync(transportMessage); await Task.Delay(600000); } catch { await _pendingMessage.Abort(); _pendingMessage = null; throw; } } }