本文整理汇总了C#中BlockingCollection.Random方法的典型用法代码示例。如果您正苦于以下问题:C# BlockingCollection.Random方法的具体用法?C# BlockingCollection.Random怎么用?C# BlockingCollection.Random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockingCollection
的用法示例。
在下文中一共展示了BlockingCollection.Random方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConcurrentlyManageFiles
public virtual async Task CanConcurrentlyManageFiles() {
await ResetAsync();
IFileStorage storage = GetStorage();
if (storage == null)
return;
using (storage) {
const string queueFolder = "q";
var queueItems = new BlockingCollection<int>();
var info = await storage.GetFileInfoAsync("nope");
Assert.Null(info);
await Run.InParallel(10, async i => {
var ev = new PostInfo {
ApiVersion = 2,
CharSet = "utf8",
ContentEncoding = "application/json",
Data = Encoding.UTF8.GetBytes("{}"),
IpAddress = "127.0.0.1",
MediaType = "gzip",
ProjectId = i.ToString(),
UserAgent = "test"
};
await storage.SaveObjectAsync(Path.Combine(queueFolder, i + ".json"), ev);
queueItems.Add(i);
});
Assert.Equal(10, (await storage.GetFileListAsync()).Count());
await Run.InParallel(10, async i => {
string path = Path.Combine(queueFolder, queueItems.Random() + ".json");
var eventPost = await storage.GetEventPostAndSetActiveAsync(Path.Combine(queueFolder, RandomData.GetInt(0, 25) + ".json"));
if (eventPost == null)
return;
if (RandomData.GetBool()) {
await storage.CompleteEventPost(path, eventPost.ProjectId, DateTime.UtcNow, true);
} else
await storage.SetNotActiveAsync(path);
});
}
}