当前位置: 首页>>代码示例>>C#>>正文


C# Race.RunAs方法代码示例

本文整理汇总了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);
        }
开发者ID:lcorneliussen,项目名称:Braindrops,代码行数:29,代码来源:RaceTest.cs

示例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);
        }
开发者ID:lcorneliussen,项目名称:Braindrops,代码行数:15,代码来源:RaceTest.cs

示例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();
        }
开发者ID:lcorneliussen,项目名称:Braindrops,代码行数:25,代码来源:RaceTest.cs


注:本文中的Race.RunAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。