本文整理汇总了C#中Channels.TrySelect方法的典型用法代码示例。如果您正苦于以下问题:C# Channels.TrySelect方法的具体用法?C# Channels.TrySelect怎么用?C# Channels.TrySelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Channels
的用法示例。
在下文中一共展示了Channels.TrySelect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrySelect_returns_minus_one_if_no_channels_are_ready
public void TrySelect_returns_minus_one_if_no_channels_are_ready()
{
var ch1 = new Channel<int>();
var ch2 = new Channel<bool>(1);
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.TrySelect();
Assert.AreEqual(-1, got.Index, "index");
}
}
示例2: TrySelect_on_all_closed_Channels_return_any_channel
public void TrySelect_on_all_closed_Channels_return_any_channel()
{
var ch1 = new Channel<int>();
var ch2 = new Channel<bool>();
ch1.Close();
ch2.Close();
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.TrySelect();
Assert.AreNotEqual(-1, got.Index, "index");
}
}
示例3: TrySelect_returns_if_one_channel_is_ready_to_read
public void TrySelect_returns_if_one_channel_is_ready_to_read()
{
var ch1 = new Channel<int>();
var ch2 = new Channel<bool>(1);
ThreadPool.QueueUserWorkItem(state => ch1.Send(123));
Thread.Sleep(50);
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.TrySelect();
Assert.AreEqual(0, got.Index, "index");
}
}
示例4: tryrecv_returns_if_the_other_channel_is_ready
public void tryrecv_returns_if_the_other_channel_is_ready()
{
var ch1 = new Channel<int>();
var ch2 = new Channel<bool>(1);
var sent = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(state => { ch2.Send(true); sent.Set(); });
sent.WaitOne();
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.TrySelect();
Assert.AreEqual(1, got.Index, "index");
}
}