示例#1
0
        //Method to load the search window
        private void btnSearch_Click(object sender, EventArgs e)
        {
            hideForms();

            //Get user search text
            String searchText = txtSearchBox.Text;

            //Create a new song model
            SongModel songModel = new SongModel();
            PlaylistModel playlistModel = new PlaylistModel();

            //Populate song list with songs that fit the criteria
            List<Song> songs = new List<Song>();
            Thread songThread = new Thread(() => { songs = songModel.searchSongs(searchText); });
            songThread.Start();

            //Populate artist list with artists that fir the criteria
            List<String> artists = new List<String>();
            Thread artistThread = new Thread(() => { artists = songModel.searchArtists(searchText.ToLower()); });
            artistThread.Start();

            //Populate artist list with artists that fir the criteria
            List<Playlist> playlists = new List<Playlist>();
            Thread playlistThread = new Thread(() => { playlists = playlistModel.searchPlaylists(searchText); });
            playlistThread.Start();

            //Join threads
            songThread.Join();
            artistThread.Join();
            playlistThread.Join();

            //Call method to load results window
            loadSearchResults(songs, artists, playlists, searchText);
        }