本文整理汇总了C#中BlockingCollection.First方法的典型用法代码示例。如果您正苦于以下问题:C# BlockingCollection.First方法的具体用法?C# BlockingCollection.First怎么用?C# BlockingCollection.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockingCollection
的用法示例。
在下文中一共展示了BlockingCollection.First方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationException
public void Publish_Where_Channel_Publication_Fails_Results_In_A_Non_Completed_Publication_Task_Which_Is_Placed_Back_On_The_Publication_Queue()
{
var _connection = Substitute.For<IConnection>();
var _channel = Substitute.For<IModel>();
var _publicationQueue = new BlockingCollection<Publication>();
_connection.CreateModel().Returns(_channel);
_channel
.When(channel => channel.BasicPublish(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IBasicProperties>(), Arg.Any<byte[]>()))
.Do(callInfo => { throw new ApplicationException("Bang !"); });
var _messageDelivery = new MessageDelivery("EXCHANGE", typeof(MyEvent).Name, MessageDeliveryMode.Persistent, message => "ARoutingKey");
var _myEvent = new MyEvent(Guid.NewGuid(), "CorrlationId_1", "Detail", 1);
var _taskCompletionSource = new TaskCompletionSource<PublicationResult>();
var _publication = new Publication(_messageDelivery, _myEvent, _taskCompletionSource);
var _SUT = new Publisher(_connection, _publicationQueue, CancellationToken.None);
var _publisherTask = _SUT.Start();
_publicationQueue.Add(_publication);
try { _publisherTask.Wait(); } catch { }
Assert.IsFalse(_publication.ResultTask.IsCompleted);
Assert.AreSame(_publication, _publicationQueue.First());
}