Beispiel #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();
            }
        }
Beispiel #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");
        }
Beispiel #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();
         }
     }
 }