本文整理汇总了C#中Race.RunAs方法的典型用法代码示例。如果您正苦于以下问题:C# Race.RunAs方法的具体用法?C# Race.RunAs怎么用?C# Race.RunAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Race
的用法示例。
在下文中一共展示了Race.RunAs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _testSimple
private IEnumerable<RaceControl<string>> _testSimple(Race<string> race)
{
Console.WriteLine("operation called on thread {0}, name '{1}'", Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.Name);
int nId = Thread.CurrentThread.ManagedThreadId;
yield return race.RunAs("x");
Console.WriteLine("Should be in x");
Console.WriteLine("operation called on thread {0}, name '{1}'", Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.Name);
int xId = Thread.CurrentThread.ManagedThreadId;
Assert.AreNotEqual(nId, xId);
yield return race.RunAs("y");
Console.WriteLine("Should be in y");
Console.WriteLine("operation called on thread {0}, name '{1}'", Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.Name);
int yId = Thread.CurrentThread.ManagedThreadId;
Assert.AreNotEqual(nId, yId);
Assert.AreNotEqual(xId, nId);
yield return race.RunAs("x");
Console.WriteLine("Should be in x again");
Console.WriteLine("operation called on thread {0}, name '{1}'", Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.Name);
Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, xId);
}
示例2: _testAsync
private IEnumerable<RaceControl<string>> _testAsync(Race<string> race)
{
5.Log("Wait anywhere");
Thread.Sleep(5);
yield return race.RunAsync("a", () =>
{
5.Log("Wait in a?");
Thread.Sleep(10);
});
yield return race.RunAs("b");
10.Log("Wait in b?");
Thread.Sleep(5);
}
示例3: _testThreadStatic
private IEnumerable<RaceControl<Formula1Teams>> _testThreadStatic(Race<Formula1Teams> race)
{
yield return race.RunAs(Formula1Teams.Ferrari);
x.ShouldEqual(0);
x++;
x.ShouldEqual(1).Log();
yield return race.RunAs(Formula1Teams.BmwSauber);
x.ShouldEqual(0);
x++;
x.ShouldEqual(1).Log();
yield return race.RunAs(Formula1Teams.Ferrari);
x.ShouldEqual(1);
x++;
x++;
x.ShouldEqual(3).Log();
yield return race.RunAs(Formula1Teams.BmwSauber);
x.ShouldEqual(1).Log();
}