本文整理汇总了C#中Task.GetResultNonLocking方法的典型用法代码示例。如果您正苦于以下问题:C# Task.GetResultNonLocking方法的具体用法?C# Task.GetResultNonLocking怎么用?C# Task.GetResultNonLocking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.GetResultNonLocking方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResultNonLocking_timeout_silent_fail_nullable_type
public void GetResultNonLocking_timeout_silent_fail_nullable_type()
{
var task = new Task<string>(() => { Thread.Sleep(1000); return "test"; });
task.Start();
var result = task.GetResultNonLocking(TimeSpan.FromMilliseconds(50), throwOnTimeout: false);
Assert.IsNull(result);
Assert.IsFalse(task.IsCompleted);
}
示例2: GetResultNonLocking_timeout_silent_fail
public void GetResultNonLocking_timeout_silent_fail()
{
var task = new Task<int>(() => { Thread.Sleep(1000); return 500; });
task.Start();
var result = task.GetResultNonLocking(TimeSpan.FromMilliseconds(50), throwOnTimeout: false);
Assert.AreEqual(0, result);
Assert.IsFalse(task.IsCompleted);
}
示例3: GetResultNonLocking_success
public void GetResultNonLocking_success()
{
var task = new Task<int>(() => { Thread.Sleep(50); return 1000; });
task.Start();
var result = task.GetResultNonLocking(TimeSpan.FromMilliseconds(100));
Assert.AreEqual(1000, result);
Assert.IsTrue(task.IsCompleted);
}
示例4: GetResultNonLocking_success_nullable_type
public void GetResultNonLocking_success_nullable_type()
{
var task = new Task<string>(() => { Thread.Sleep(50); return "test"; });
task.Start();
var result = task.GetResultNonLocking(TimeSpan.FromMilliseconds(100));
Assert.AreEqual("test", result);
Assert.IsTrue(task.IsCompleted);
}
示例5: GetResultNonLocking_timeout_exception
public void GetResultNonLocking_timeout_exception()
{
var task = new Task<int>(() => { Thread.Sleep(1000); return 1000; });
task.Start();
Assert.Throws<TimeoutException>(() => task.GetResultNonLocking(TimeSpan.FromMilliseconds(200)));
}