Esempio n. 1
0
        async private Task InitializeAsync()
        {
            try
            {
                InitializeCts = new CancellationTokenSource();
                await Task.Factory.StartNew(() => mm = new MediaMonkeyNet.MediaMonkeyNet(), InitializeCts.Token);

                await Task.Factory.StartNew(() => Player = new Player(mm), InitializeCts.Token);
            }
            catch (Exception ex)
            {
                mm = null;
                Dispose();
            }
        }
Esempio n. 2
0
        public void Dispose()
        {
            if (InitializeCts != null)
            {
                InitializeCts.Cancel();
            }
            if (RefreshPlayerCts != null)
            {
                RefreshPlayerCts.Cancel();
            }
            if (RefreshTrackCts != null)
            {
                RefreshTrackCts.Cancel();
            }
            if (RefreshCoverCts != null)
            {
                RefreshCoverCts.Cancel();
            }

            if (!IsRunning())
            {
                // In a lot of cases the remote socket for chrome is
                // busy for a second and won't reply immediately
                // it's fine to cancel updates and reinitialize to prevent other issues
                // but immediately clearing the cached objects would cause the values
                // to 'flicker' since rainmeter immediately clears the values
                // only null them if the process is gone, indicating that mm actually shut down

                this.ClearCachedData();
            }

            if (mm != null)
            {
                try
                {
                    if (IsRunning())
                    {
                        if (mm != null)
                        {
                            mm.Dispose();
                        }
                    }
                }
                catch { }
                mm = null;
            }
        }