Stop() public method

public Stop ( ) : void
return void
Esempio n. 1
0
        public void TryEnter(int milliSeconds, ref bool lockTaken)
        {
            //Thread.BeginCriticalRegion();

            Watch sw = Watch.StartNew();

            while (sw.ElapsedMilliseconds < milliSeconds)
            {
                TryEnter(ref lockTaken);
            }
            sw.Stop();
        }
Esempio n. 2
0
        public bool Wait(int timeoutMilli, CancellationToken token)
        {
            if (timeoutMilli == -1)
            {
                Wait();
                return(true);
            }

            Watch sw      = Watch.StartNew();
            long  timeout = (long)timeoutMilli;

            bool result = Wait(() => sw.ElapsedMilliseconds > timeout || token.IsCancellationRequested);

            sw.Stop();

            return(result);
        }
Esempio n. 3
0
        public bool Wait(int timeoutMilli)
        {
            if (timeoutMilli == -1)
            {
                Wait();
                return(true);
            }

            Watch sw      = Watch.StartNew();
            long  timeout = (long)timeoutMilli;

            bool result = Wait(() => sw.ElapsedMilliseconds > timeout);

            sw.Stop();

            return(result);
        }
Esempio n. 4
0
        public bool Wait(int millisecondsTimeout)
        {
            CheckState();
            if (millisecondsTimeout < -1)
            {
                throw new ArgumentOutOfRangeException("millisecondsTimeout",
                                                      "millisecondsTimeout is a negative number other than -1");
            }
            if (millisecondsTimeout == -1)
            {
                Wait();
                return(true);
            }

            do
            {
                int result = Interlocked.Decrement(ref currCount);
                if (result >= 0)
                {
                    break;
                }

                // We revert back the operation
                result = Interlocked.Increment(ref currCount);
                Watch sw = Watch.StartNew();
                while (Thread.VolatileRead(ref currCount) <= 0)
                {
                    if (sw.ElapsedMilliseconds > millisecondsTimeout)
                    {
                        sw.Stop();
                        return(false);
                    }
                    wait.SpinOnce();
                }
            } while (true);

            return(true);
        }