Exemplo n.º 1
0
        public void Stop()
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            #endregion

            lock (lockObject)
            {
                #region Guard

                if (!playing)
                {
                    return;
                }

                #endregion

                playing = false;
                clock.Stop();
                stopper.AllSoundOff();
            }
        }
Exemplo n.º 2
0
        public void Stop()
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            #endregion

            Console.WriteLine($"3-Before lock in Stop");
            lock (lockObject)
            {
                Console.WriteLine($"3-in lock in Stop");
                #region Guard

                if (!playing)
                {
                    return;
                }

                #endregion

                playing = false;
                clock.Stop();
                stopper.AllSoundOff();
            }
            Console.WriteLine($"3-After lock in Stop");
        }
Exemplo n.º 3
0
        public void Stop()
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            #endregion

            Console.WriteLine($"3-Before lock in Stop");

            // attempts to acquire an exclusive lock on lockObject
            #region try to lock lockObject
            if (Monitor.TryEnter(lockObject))
            {
                try
                {
                    Console.WriteLine($"3-in lock in Stop");
                    #region Guard

                    if (!playing)
                    {
                        return;
                    }

                    #endregion

                    playing = false;
                    clock.Stop();
                    stopper.AllSoundOff();
                }
                finally
                {
                    Monitor.Exit(lockObject);
                }
            }

            /*lock (lockObject)
             * {
             *  Console.WriteLine($"3-in lock in Stop");
             #region Guard
             *
             *  if (!playing)
             *  {
             *      return;
             *  }
             *
             #endregion
             *
             *  playing = false;
             *  clock.Stop();
             *  stopper.AllSoundOff();
             * }
             */
            Console.WriteLine($"3-After lock in Stop");
            #endregion
        }
 public void Stop()
 {
     if (playing)
     {
         lock (lockObject)
         {
             playing = false;
             clock.Stop();
             stopper.AllSoundOff();
         }
     }
 }