//The following method is part of the lab. When a thumbnail is requested, provide it on demand
        //by loading an image from a resource.
        private void TabbedThumbnail_TabbedThumbnailBitmapRequested(object sender, TabbedThumbnailEventArgs e)
        {
            //if (_sneakySource == null)
            //{
            //    _sneakySource = new BitmapImage();
            //    _sneakySource.BeginInit();
            //    _sneakySource.DecodePixelHeight = 200;
            //    _sneakySource.UriSource = new Uri("pack://application:,,,/assets/SpeedyGonzales.jpg");
            //    _sneakySource.EndInit();
            ////}
            Bitmap preview = new Bitmap(nowPlayingFile.GetImageFile(MJImageFileFlags.IMAGEFILE_THUMBNAIL_MEDIUM));

            e.TabbedThumbnail.SetImage(preview);
            e.TabbedThumbnail.DisplayFrameAroundBitmap = false;
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            playback = mcRef.GetPlayback();
            //customWindow = Windows7.DesktopIntegration.CustomWindowsManager.CreateWindowsManager((IntPtr)mcRef.GetWindowHandle(), IntPtr.Zero);
            //IMJFileAutomation nowPlayingFile;
            //nowPlayingFile = mcRef.GetCurPlaylist().GetFile(mcRef.GetCurPlaylist().Position);

            int i = 0;

            string prevFile = "";
            string currentFile = "";
            
            while (playback.State != MJPlaybackStates.PLAYSTATE_STOPPED)
            {
                nowPlayingFile = mcRef.GetCurPlaylist().GetFile(mcRef.GetCurPlaylist().Position);

                setWindowsPeak();
                if (enableCoverArt.Checked)
                {
                    Windows7Taskbar.EnableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                    currentFile = nowPlayingFile.GetImageFile(MJImageFileFlags.IMAGEFILE_THUMBNAIL_MEDIUM);
                    if (!string.IsNullOrEmpty(currentFile))
                    {
                        if (currentFile != prevFile)
                        {
                            setPreview(currentFile);
                        }
                    }
                    else
                    {
                        Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                    }

                    prevFile = currentFile;
                }
                else
                {
                    Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                }
                
                
                createThumbnail(getDisplayWindowHandle());
                if (trackProgress.Checked)
                {
                    if (playback.State == MJPlaybackStates.PLAYSTATE_PLAYING)
                    {
                        windowsTaskbar.SetProgressState(TaskbarProgressBarState.Normal);
                        addUserInfoText("Duration: " + playback.Duration);
                        if (nowPlayingFile.Duration <= 0) windowsTaskbar.SetProgressState(TaskbarProgressBarState.Indeterminate);
                        else
                        {
                            if (playback.Position >= 0) windowsTaskbar.SetProgressValue(playback.Position, nowPlayingFile.Duration);
                        }
                    }
                    else if (playback.State == MJPlaybackStates.PLAYSTATE_PAUSED) windowsTaskbar.SetProgressState(TaskbarProgressBarState.Paused);
                }

                else if (playlistProgress.Checked)
                {
                    windowsTaskbar.SetProgressState(playback.State != MJPlaybackStates.PLAYSTATE_PAUSED ? TaskbarProgressBarState.Normal : TaskbarProgressBarState.Paused);
                    windowsTaskbar.SetProgressValue(mcRef.GetCurPlaylist().Position, mcRef.GetCurPlaylist().GetNumberFiles());
                }

                else
                {
                    windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
                }
                setWindowTitle();
                System.Threading.Thread.Sleep(500);
                GC.Collect();
                i++;
            }
            //Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
            windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
            return; 
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            playback = mcRef.GetPlayback();
            //customWindow = Windows7.DesktopIntegration.CustomWindowsManager.CreateWindowsManager((IntPtr)mcRef.GetWindowHandle(), IntPtr.Zero);
            //IMJFileAutomation nowPlayingFile;
            //nowPlayingFile = mcRef.GetCurPlaylist().GetFile(mcRef.GetCurPlaylist().Position);

            int i = 0;

            string prevFile    = "";
            string currentFile = "";

            while (playback.State != MJPlaybackStates.PLAYSTATE_STOPPED)
            {
                nowPlayingFile = mcRef.GetCurPlaylist().GetFile(mcRef.GetCurPlaylist().Position);

                setWindowsPeak();
                if (enableCoverArt.Checked)
                {
                    Windows7Taskbar.EnableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                    currentFile = nowPlayingFile.GetImageFile(MJImageFileFlags.IMAGEFILE_THUMBNAIL_MEDIUM);
                    if (!string.IsNullOrEmpty(currentFile))
                    {
                        if (currentFile != prevFile)
                        {
                            setPreview(currentFile);
                        }
                    }
                    else
                    {
                        Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                    }

                    prevFile = currentFile;
                }
                else
                {
                    Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
                }


                createThumbnail(getDisplayWindowHandle());
                if (trackProgress.Checked)
                {
                    if (playback.State == MJPlaybackStates.PLAYSTATE_PLAYING)
                    {
                        windowsTaskbar.SetProgressState(TaskbarProgressBarState.Normal);
                        addUserInfoText("Duration: " + playback.Duration);
                        if (nowPlayingFile.Duration <= 0)
                        {
                            windowsTaskbar.SetProgressState(TaskbarProgressBarState.Indeterminate);
                        }
                        else
                        {
                            if (playback.Position >= 0)
                            {
                                windowsTaskbar.SetProgressValue(playback.Position, nowPlayingFile.Duration);
                            }
                        }
                    }
                    else if (playback.State == MJPlaybackStates.PLAYSTATE_PAUSED)
                    {
                        windowsTaskbar.SetProgressState(TaskbarProgressBarState.Paused);
                    }
                }

                else if (playlistProgress.Checked)
                {
                    windowsTaskbar.SetProgressState(playback.State != MJPlaybackStates.PLAYSTATE_PAUSED ? TaskbarProgressBarState.Normal : TaskbarProgressBarState.Paused);
                    windowsTaskbar.SetProgressValue(mcRef.GetCurPlaylist().Position, mcRef.GetCurPlaylist().GetNumberFiles());
                }

                else
                {
                    windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
                }
                setWindowTitle();
                System.Threading.Thread.Sleep(500);
                GC.Collect();
                i++;
            }
            //Windows7Taskbar.DisableCustomWindowPreview((IntPtr)mcRef.GetWindowHandle());
            windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
            return;
        }