private object DoSomeWork(object state)
        {
            int sleepTime = (int)state;
            int newX      = Interlocked.Increment(ref _x);

            //Console.WriteLine("{0}: Enter, newX = {1}", DateTime.Now.ToLongTimeString(), newX);
            //Console.WriteLine("{0}: Sleeping for {1} ms", DateTime.Now.ToLongTimeString(), sleepTime);
            Thread.Sleep(sleepTime);
            newX = Interlocked.Increment(ref _x);
            //Console.WriteLine("{0}: Leave, newX = {1}", DateTime.Now.ToLongTimeString(), newX);
            return(1);
        }
        private object DoWork(object state)
        {
            int wigsIndex = (int)state;

            int val = Interlocked.Increment(ref _concurrentOps[wigsIndex]);

            _success = _success && (val <= _concurrencyPerWig);

            int waitTime = _randGen.Next(50);

            Thread.Sleep(waitTime);

            val      = Interlocked.Decrement(ref _concurrentOps[wigsIndex]);
            _success = _success && (val >= 0);

            return(null);
        }
 private object DoSomeWork(object state)
 {
     Debug.WriteLine(Interlocked.Increment(ref x));
     Thread.Sleep(1000);
     return(1);
 }
Ejemplo n.º 4
0
 public void Increment()
 {
     Interlocked.Increment(ref _counter);
 }