Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Fix a race condition that breaks Spotify title updates (title update …
Browse files Browse the repository at this point in the history
…thread stopped)
  • Loading branch information
protyposis committed Dec 2, 2014
1 parent 822217a commit b924832
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion LocalAudioBroadcast/Metadata/Spotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Runtime.CompilerServices;

namespace LocalAudioBroadcast.Metadata {
/// <summary>
Expand Down Expand Up @@ -98,12 +99,14 @@ public void RequestTrackInfo() {
}

public event EventHandler<TrackInfoChangedEventArgs> TrackInfoChanged {
[MethodImpl(MethodImplOptions.Synchronized)]
add {
if (_TrackInfoChanged == null) {
Start();
}
_TrackInfoChanged += value;
}
[MethodImpl(MethodImplOptions.Synchronized)]
remove {
_TrackInfoChanged -= value;
if (_TrackInfoChanged == null) {
Expand All @@ -113,11 +116,16 @@ public event EventHandler<TrackInfoChangedEventArgs> TrackInfoChanged {
}

private void Start() {
/* When Stop() gets called, it sets _threadShouldStop to true,
* but it can still take a while until the thread finally stops.
* On a Start() call, such a stop can be cancelled by setting
* _threadShouldStop back to false. */
_threadShouldStop = false;

if (_threadRunning) {
return;
}

_threadShouldStop = false;
_threadRunning = true;

UpdateSpotifyProcess();
Expand Down

0 comments on commit b924832

Please sign in to comment.