[longomatch] Make sure timers are disposed correctly
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Make sure timers are disposed correctly
- Date: Tue, 31 Mar 2015 17:35:10 +0000 (UTC)
commit b604f6250b6a5ac7300f6ea955ca5ff0096249b3
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Mar 25 20:52:05 2015 +0100
Make sure timers are disposed correctly
LongoMatch.Core/Common/Seeker.cs | 10 +++++-
LongoMatch.Services/Services/PlayerController.cs | 33 +++++++++++++--------
2 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Seeker.cs b/LongoMatch.Core/Common/Seeker.cs
index 94b94ac..d467260 100644
--- a/LongoMatch.Core/Common/Seeker.cs
+++ b/LongoMatch.Core/Common/Seeker.cs
@@ -17,7 +17,8 @@ namespace LongoMatch.Core.Common
Time start;
float rate;
SeekType seekType;
- Timer timer;
+ readonly Timer timer;
+ readonly ManualResetEvent TimerDisposed;
public Seeker (uint timeoutMS = 80)
{
@@ -26,14 +27,19 @@ namespace LongoMatch.Core.Common
disposed = false;
seekType = SeekType.None;
timer = new Timer (HandleSeekTimeout);
+ TimerDisposed = new ManualResetEvent (false);
}
#region IDisposable implementation
public void Dispose ()
{
+ if (!disposed) {
+ timer.Dispose (TimerDisposed);
+ TimerDisposed.WaitOne ();
+ TimerDisposed.Dispose ();
+ }
disposed = true;
- timer.Dispose ();
}
#endregion
diff --git a/LongoMatch.Services/Services/PlayerController.cs
b/LongoMatch.Services/Services/PlayerController.cs
index 3d105bc..13ce7fb 100644
--- a/LongoMatch.Services/Services/PlayerController.cs
+++ b/LongoMatch.Services/Services/PlayerController.cs
@@ -51,11 +51,12 @@ namespace LongoMatch.Services
List<IntPtr> windowHandles;
Time streamLenght, videoTS, imageLoadedTS;
- bool readyToSeek, stillimageLoaded, ready, delayedOpen;
+ bool readyToSeek, stillimageLoaded, ready, delayedOpen, disposed;
Seeker seeker;
Segment loadedSegment;
PendingSeek pendingSeek;
- Timer timer;
+ readonly Timer timer;
+ readonly ManualResetEvent TimerDisposed;
struct Segment
{
@@ -86,6 +87,7 @@ namespace LongoMatch.Services
streamLenght = new Time (0);
Step = new Time (5000);
timer = new Timer (HandleTimeout);
+ TimerDisposed = new ManualResetEvent (false);
ready = false;
CreatePlayer ();
}
@@ -202,17 +204,22 @@ namespace LongoMatch.Services
public void Dispose ()
{
- Log.Debug ("Disposing PlayerController");
- ReconfigureTimeout (0);
- IgnoreTicks = true;
- seeker.Dispose ();
- timer.Dispose ();
- player.Error -= HandleError;
- player.StateChange -= HandleStateChange;
- player.Eos -= HandleEndOfStream;
- player.ReadyToSeek -= HandleReadyToSeek;
- player.Dispose ();
- FileSet = null;
+ if (!disposed) {
+ Log.Debug ("Disposing PlayerController");
+ ReconfigureTimeout (0);
+ IgnoreTicks = true;
+ seeker.Dispose ();
+ timer.Dispose (TimerDisposed);
+ TimerDisposed.WaitOne ();
+ TimerDisposed.Dispose ();
+ player.Error -= HandleError;
+ player.StateChange -= HandleStateChange;
+ player.Eos -= HandleEndOfStream;
+ player.ReadyToSeek -= HandleReadyToSeek;
+ player.Dispose ();
+ FileSet = null;
+ }
+ disposed = true;
}
public void Ready ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]