本文整理汇总了C#中AsyncQueue.Post方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue.Post方法的具体用法?C# AsyncQueue.Post怎么用?C# AsyncQueue.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncQueue
的用法示例。
在下文中一共展示了AsyncQueue.Post方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunAsyncQueueAsync
public static async Task RunAsyncQueueAsync(int count)
{
var cancellationToken = CancellationToken.None;
var target = new AsyncQueue<string>(count, count);
var PostTasks = new Task[count];
var dequeueTasks = new Task<string>[count];
var PostSetupTask = Task.Run(() =>
{
for (int i = 0; i < count; i++)
{
var item = "HVQFSW613ACT65DOS2ILBA4G4QB3UP3K4PPZPB7UZ771SX9TX7DVNZR82W1TSHWDBZHIE8V6CGILADRFQ3QA76BOYA4T3XS7A8OQ3I2FCT8X04L2GXR3RY23WB2A0ZLNT58WCMZTY54PRPOVVENCMOJMCZC6D85H9HPGJ58BBOHN7PJ0G3QTDSB8K4ACT26QXG5D30WI";
PostTasks[i] = Task.Run(() => target.Post(item));
}
});
var dequeueSetupTask = Task.Run(() =>
{
for (int i = 0; i < count; i++)
{
dequeueTasks[i] = target.ReceiveAsync(cancellationToken);
}
});
await Task.WhenAll(PostSetupTask, dequeueSetupTask);
await Task.WhenAll(dequeueTasks);
await Task.WhenAll(PostTasks);
if (target.BufferCount != 0 ||
target.PromisesCount != 0)
{
System.Console.WriteLine("AsyncQueue - Not empty");
}
}