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


C# Semaphore.Acquire方法代码示例

本文整理汇总了C#中System.Threading.Semaphore.Acquire方法的典型用法代码示例。如果您正苦于以下问题:C# Semaphore.Acquire方法的具体用法?C# Semaphore.Acquire怎么用?C# Semaphore.Acquire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Semaphore的用法示例。


在下文中一共展示了Semaphore.Acquire方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PerformTest

        public override void PerformTest()
        {
            _testRunning = true;

            Log("Creating DOM elements");

            IDomElement element1 = DomManager.CreateElement("DIV");
            element1.Style.BackgroundColor = "blue";
            element1.Style.Top = "250px";
            element1.Style.Left = "150px";

            IDomElement element2 = DomManager.CreateElement("DIV");
            element2.Style.BackgroundColor = "red";
            element2.Style.Top = "250px";
            element2.Style.Left = "150px";

            IDomElement element3 = DomManager.CreateElement("DIV");
            element3.Style.BackgroundColor = "orange";
            element3.Style.Top = "250px";
            element3.Style.Left = "350px";

            IDomElement element4 = DomManager.CreateElement("DIV");
            element4.Style.BackgroundColor = "green";
            element4.Style.Top = "250px";
            element4.Style.Left = "350px";

            IDomDocument document = DomManager.Document;
            IDomElement documentElement = DomManager.GetDocumentBody();
            IDomElement[] elements = new IDomElement[] {
                element1,
                element2,
                element3,
                element4
            };

            _semaphore = new Semaphore(elements.Length);

            bool clockwise = true;
            for (int i = 0; i < elements.Length; i++, clockwise = !clockwise)
            {
                IDomElement element = elements[i];

                element.Style.Height = "90px";
                element.Style.Width = "90px";
                element.Style.Position = "absolute";

                bool clockwiseForThisElement = clockwise;
                documentElement.AppendChild(element);
                Thread thread = new Thread(delegate()
                {
                    Log("Starting thread to move element " + element + ".  Clockwise = " + clockwiseForThisElement);
                    MoveElement("element " + i, element, clockwiseForThisElement);
                }, ThreadPriority.Normal);
                thread.Name = "DomTest animation: " + element.Style.BackgroundColor;
                thread.Start();
            }

            Log("Sleeping for " + _duration + " seconds");

            Thread.Sleep(_duration * 1000);

            Log("Woke up!");
            _testRunning = false;
            _semaphore.Acquire(elements.Length);
        }
开发者ID:sidecut,项目名称:xaeios,代码行数:65,代码来源:DomTest.cs


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