Пример #1
0
        public static int WaitAny(CEventHandle[] waitHandles, int millisecondsTimeout)
        {
            if (millisecondsTimeout < Timeout.Infinite)
            {
                throw new ArgumentOutOfRangeException("millisecondsTimeout");
            }

            if (waitHandles == null || waitHandles.Any(w => w == null))
            {
                throw new ArgumentNullException("waitHandles");
            }

            long endTime = millisecondsTimeout == Timeout.Infinite ? Int64.MaxValue : millisecondsTimeout;
            var  sw      = Stopwatch.StartNew();

            int sleepTime = 0;

            while (sw.ElapsedMilliseconds < endTime)
            {
                for (int ix = 0; ix < waitHandles.Length; ++ix)
                {
                    if (waitHandles[ix].Wait(0))
                    {
                        return(ix);
                    }
                }
                CrestronEnvironment.Sleep(++sleepTime);
            }

            return(WaitTimeout);
        }
Пример #2
0
 public static void Sleep(int timeoutInMsec)
 {
     CrestronEnvironment.Sleep(timeoutInMsec);
 }