[longomatch] Make the Seeker IDisposable and dispose it in the controller



commit 906a75e5eb8582be3c10d02e0fe31359ebb01ee8
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Mar 25 19:07:57 2015 +0100

    Make the Seeker IDisposable and dispose it in the controller

 LongoMatch.Core/Common/Seeker.cs                 |   23 +++++++++++++++++++--
 LongoMatch.Services/Services/PlayerController.cs |    1 +
 2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Seeker.cs b/LongoMatch.Core/Common/Seeker.cs
index ddbe91a..94b94ac 100644
--- a/LongoMatch.Core/Common/Seeker.cs
+++ b/LongoMatch.Core/Common/Seeker.cs
@@ -1,17 +1,19 @@
-using LongoMatch.Core.Store;
+using System;
+using System.Threading;
 using LongoMatch.Core.Handlers;
+using LongoMatch.Core.Store;
 using Timer = System.Threading.Timer;
-using System.Threading;
 
 namespace LongoMatch.Core.Common
 {
-       public class Seeker
+       public class Seeker: IDisposable
        {
                public event SeekHandler SeekEvent;
 
                uint timeout;
                bool pendingSeek;
                bool waiting;
+               bool disposed;
                Time start;
                float rate;
                SeekType seekType;
@@ -21,10 +23,21 @@ namespace LongoMatch.Core.Common
                {
                        timeout = timeoutMS;
                        pendingSeek = false;
+                       disposed = false;
                        seekType = SeekType.None;
                        timer = new Timer (HandleSeekTimeout);
                }
 
+               #region IDisposable implementation
+
+               public void Dispose ()
+               {
+                       disposed = true;
+                       timer.Dispose ();
+               }
+
+               #endregion
+
                public void Seek (SeekType seekType, Time start = null, float rate = 1)
                {
                        this.seekType = seekType;
@@ -43,6 +56,10 @@ namespace LongoMatch.Core.Common
 
                void HandleSeekTimeout (object state)
                {
+                       if (disposed) {
+                               return;
+                       }
+
                        waiting = false;
                        if (pendingSeek) {
                                if (seekType != SeekType.None) {
diff --git a/LongoMatch.Services/Services/PlayerController.cs 
b/LongoMatch.Services/Services/PlayerController.cs
index 7097a62..9ae004a 100644
--- a/LongoMatch.Services/Services/PlayerController.cs
+++ b/LongoMatch.Services/Services/PlayerController.cs
@@ -202,6 +202,7 @@ namespace LongoMatch.Services
                {
                        Log.Debug ("Disposing PlayerController");
                        IgnoreTicks = true;
+                       seeker.Dispose ();
                        timer.Dispose ();
                        player.Error -= HandleError;
                        player.StateChange -= HandleStateChange;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]