private void GetUserMusicAsync()
        {
            IsBusy = true;
            _backgroundWorker.DoWork += (sender, e) =>
            {
                //App.Current.Dispatcher.BeginInvoke((Action)(() =>
                //{
                string     path  = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                var        dir   = new DirectoryInfo(path);
                FileInfo[] files = dir.GetFiles("*.mp3", SearchOption.AllDirectories);
                foreach (var musicInfo in files.Select(file => new MusicInfo(file.FullName)))
                {
                    AllMusicCollection.Add(musicInfo);
                }
                files = dir.GetFiles("*.wma", SearchOption.AllDirectories);
                foreach (var musicInfo in files.Select(file => new MusicInfo(file.FullName)))
                {
                    AllMusicCollection.Add(musicInfo);
                }
                //}));
            };
            _backgroundWorker.RunWorkerCompleted += (sender, e) =>
            {
                IsBusy = false;

                var msg = new MusicLoadedMessage
                {
                    AllMusic = AllMusicCollection
                };
                Messenger.Default.Send(msg);
            };
            _backgroundWorker.RunWorkerAsync();
        }
Esempio n. 2
0
        void SortMusic()
        {
            var tempCollection = new ObservableCollection <MusicInfo>(AllMusicCollection);
            var musics         = from music in tempCollection
                                 orderby music.Title
                                 select music;

            AllMusicCollection.Clear();
            foreach (var music in musics)
            {
                AllMusicCollection.Add(music);
            }
        }