mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Timer should be disabled and events detached if no longer needed.
So IDisposable is introduced which handles the above...
This commit is contained in:
parent
234a522f8f
commit
08137421ea
@ -8,7 +8,7 @@ using System.Timers;
|
||||
|
||||
namespace SpotifyAPI.Local
|
||||
{
|
||||
public class SpotifyLocalAPI
|
||||
public class SpotifyLocalAPI : IDisposable
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||
@ -49,7 +49,7 @@ namespace SpotifyAPI.Local
|
||||
private const int KeyeventfKeyup = 0x2;
|
||||
|
||||
private readonly RemoteHandler _rh;
|
||||
private readonly Timer _eventTimer;
|
||||
private Timer _eventTimer;
|
||||
private StatusResponse _eventStatusResponse;
|
||||
|
||||
public event EventHandler<TrackChangeEventArgs> OnTrackChange;
|
||||
@ -64,9 +64,21 @@ namespace SpotifyAPI.Local
|
||||
{
|
||||
_rh = new RemoteHandler();
|
||||
|
||||
AttachTimer(50);
|
||||
}
|
||||
|
||||
public SpotifyLocalAPI(int timerIntervall)
|
||||
{
|
||||
_rh = new RemoteHandler();
|
||||
|
||||
AttachTimer(timerIntervall);
|
||||
}
|
||||
|
||||
private void AttachTimer(int intervall)
|
||||
{
|
||||
_eventTimer = new Timer
|
||||
{
|
||||
Interval = 50,
|
||||
Interval = intervall,
|
||||
AutoReset = false,
|
||||
Enabled = false
|
||||
};
|
||||
@ -333,5 +345,13 @@ namespace SpotifyAPI.Local
|
||||
Process.Start(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"spotify\spotifywebhelper.exe"));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_eventTimer == null)
|
||||
return;
|
||||
_eventTimer.Enabled = false;
|
||||
_eventTimer.Elapsed -= ElapsedTick;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user