public void Close()
        {
            exiting = true;

            Lib.EnableNavKeys(true);
            normal.RemoveFilterIndex();

            Crawler.Stop();
            TrackWriter.Stop();

            if (rg != null)
            {
                rg.Cancel();
            }

            iTunes.Cancel = true;

            if (notifyIcon != null)
            {
                notifyIcon.Visible = false;
                notifyIcon         = null;
            }

            if (normal.Queue.Reordered && normal.Queue.PlaylistBasis.Length > 0 && (Database.GetPlaylistType(normal.Queue.PlaylistBasis) == PlaylistType.Standard))
            {
                Database.SaveStandardPlaylist(normal.Queue);
            }

            player.Dispose();

            Database.SaveSetting(SettingType.ShowSpectrumGrid, spectrumView.ShowGrid);
            Database.SaveSetting(SettingType.SpectrumGain, spectrumView.Gain);
            Database.SaveSetting(SettingType.ViewMode, (HTPCMode == HTPCMode.Normal ? "Normal" : "HTPC"));
            Database.SaveSetting(SettingType.CurrentFilter, normal.CurrentFilterName);
            Database.SaveSetting(SettingType.DecoderGain, DecoderGainDB);
            Database.SaveSetting(SettingType.ColumnStatus, normal.SerializeColumnStatus(HTPCMode.Normal));
            Database.SaveSetting(SettingType.ColumnStatusHTPC, normal.SerializeColumnStatus(HTPCMode.HTPC));
            Database.SaveSetting(SettingType.AskAboutMissingFiles, askAboutMissingFiles);
            Database.SaveSetting(SettingType.EqualizerOn, equalizer.On);
            Database.SaveSetting(SettingType.EqualizerTenBands, equalizer.NumBands == 10);
            Database.SaveSetting(SettingType.EqualizerFineControl, equalizer.FineControl);
            Database.SaveSetting(SettingType.CurrentEqualizer, equalizer.CurrentEqualizer.Name);
            Database.SaveSetting(SettingType.DownloadAlbumCovers, Track.DownloadCoverArt);
            Database.SaveSetting(SettingType.UseGlobalHotKeys, UseGlobalHotKeys);
            Database.SaveSetting(SettingType.FullScreen, Lib.FullScreen || !Lib.ManualReleaseFullScreen);
            Database.SaveSetting(SettingType.SpectrumSmall, (player.SpectrumMode == SpectrumMode.Small));
            Database.SaveSetting(SettingType.ArtSave, (int)ArtSaveOption);
            Database.SaveSetting(SettingType.TwitterOn, Twitter.On);
            Database.SaveSetting(SettingType.TwitterUserName, Twitter.UserName);
            Database.SaveSetting(SettingType.TwitterPassword, Twitter.Password);

            Database.SaveSetting(SettingType.LocalVolumeControlOnly, LocalVolumeControl);
            Database.SaveSetting(SettingType.LocalVolumeLevel, localVolumeLevel);
            Database.SaveSetting(SettingType.RunNumber, runNumber);
            Database.SaveSetting(SettingType.OutputDeviceName, player.OutputDeviceName);
            Database.SaveSetting(SettingType.TwitterMode, (int)Twitter.TwitterMode);
            Database.SaveSetting(SettingType.TagCloudMaxItems, tagCloud.MaxItems);
            Database.SaveSetting(SettingType.TagCloudColor, tagCloud.UseColor);
            Setting.Save();

            System.Drawing.Rectangle r;
            if (!Lib.FullScreen && mainForm.WindowState == FormWindowState.Normal)
            {
                r = mainForm.Bounds;
            }
            else
            {
                r = System.Drawing.Rectangle.Empty;
            }

            Database.SaveSetting(SettingType.NormalWindowBoundsX, r.X);
            Database.SaveSetting(SettingType.NormalWindowBoundsY, r.Y);
            Database.SaveSetting(SettingType.NormalWindowBoundsWidth, r.Width);
            Database.SaveSetting(SettingType.NormalWindowBoundsHeight, r.Height);

            Database.SaveSetting(SettingType.LastFMOn, lastFMOn);
            Database.SaveSetting(SettingType.LastFMUserName, lastFMUserName);
            Database.SaveSetting(SettingType.LastFMPassword, lastFMPassword);

            Database.SaveSetting(SettingType.MiniPlayerXPos, frmMiniPlayer.DefaultLocation.X);
            Database.SaveSetting(SettingType.MiniPlayerYPos, frmMiniPlayer.DefaultLocation.Y);

            Database.Close(mainForm);

            Clock.DoOnNewThreadNotBackground(TrackWriter.DeleteItemsLastChance);

            Clock.Close();
        }