private void SubsongSelectionForm_Load(object sender, EventArgs e) { Subsongs.Items.Clear(); Subsongs.Items.Add($"Checking {_filename}..."); // Start a task to load the metadata Task.Factory.StartNew(() => { var songs = _wrapper.GetSongs(_filename); Subsongs.BeginInvoke(new Action(() => { // Back on the GUI thread... Subsongs.Items.Clear(); Subsongs.Items.AddRange(songs.ToArray <object>()); Subsongs.SelectedIndex = 0; OKButton.Enabled = true; if (Subsongs.Items.Count == 1) { // If only one song, select it OkButtonClick(this, new EventArgs()); } })); }); }
private void SubsongSelectionForm_Load(object sender, EventArgs e) { Subsongs.Items.Clear(); Subsongs.Items.Add($"Checking {_filename}..."); // Start a task to load the metadata Task.Factory.StartNew(() => { var songs = _wrapper.GetSongs(_filename).ToList(); Subsongs.BeginInvoke(new Action(() => { // Back on the GUI thread... Subsongs.Items.Clear(); Subsongs.Items.AddRange(songs.ToArray <object>()); Subsongs.SelectedIndex = 0; OKButton.Enabled = true; if (songs.Count == 1 && songs[0].GetLength() > TimeSpan.Zero) { // If only one song, and it has a length, choose it OkButtonClick(this, EventArgs.Empty); } })); }); }