title: Read bulk audio files faster
body: <p>I am creating a music player in c# WinForms.
  I have read all audio files from folder-&gt;subfolders and stored them in struct list.
  I have displayed them in datagridview, I want to know which control do i need to use at this point to show all songs with a button in each row to play song? The audio files are more than 60k.</p>
  <p><strong>I have three questions regarding this</strong></p>
  <ol>
  <li>Do i need to use datagridview or list or another?</li>
  <li>how to read bulk audio files from folder and show them in a control(datagridview, list or another) faster like in few seconds?</li>
  <li>If i switch from AllMusic usercontrol to another and again click back to AllMusic usercontrol the application would again load 60k audio files to datagridview control which is time taking, what is the solution for that.</li>
  </ol>
  <p>Please help.</p>
  <p><strong>Reading audio files path and storing them in struct list</strong></p>
  <pre><code> public struct SongInfoStruct
          {
              public string Key;
              public string Value;
              public string Artist;
              public double Duration;
          };
  
  public List&lt;SongInfoStruct&gt; ReadPathFromSource(string Source)
          {
              MessageBox.Show(Source);
              var listpaths = new List&lt;SongInfoStruct&gt;();
              string[] PathsClickSong_temp = Directory.GetFiles(Source, &quot;*.*&quot;, SearchOption.AllDirectories);
              FileInfo tempInfo;
              string extentionName;
  
              foreach (string path in PathsClickSong_temp)
              {
                  tempInfo = new FileInfo(path);
                  extentionName = tempInfo.Extension.ToLower();
                  if (extentionName == &quot;.mp3&quot; || extentionName == &quot;.wav&quot;
                   || extentionName == &quot;.m4a&quot; || extentionName == &quot;.flac&quot;)
                  {
                      try
                      {
                          var item = GetSongInfo(path);
                          listpaths.Add(item);
                      }
                      catch
                      {
                          continue;
                      }
  
                  }
              }
  </code></pre>
  <p><strong>Reading audio file metadata</strong></p>
  <pre><code> public SongInfoStruct GetSongInfo(string url)
          {
              TagLib.File tagFile;
              var songinfo = new SongInfoStruct();
  
              tagFile = TagLib.File.Create(url);
  
              var songName = tagFile.Tag.Title;
              var artist = tagFile.Tag.FirstPerformer;
              var duration = tagFile.Properties.Duration.TotalSeconds;
              if (string.IsNullOrEmpty(artist))
                  artist = &quot;Unknown Artist&quot;;
              if (string.IsNullOrEmpty(songName))
              {
                  var Name = new FileInfo(url).Name;
                  songName = Path.GetFileNameWithoutExtension(Name);
              }
              songinfo = new SongInfoStruct
              {
                  Key = url,
                  Value = songName,
                  Artist = artist,
                  Duration = duration
              };
              return songinfo;
          }
  </code></pre>
  <p><strong>Reading struct list to store in datatable to set datagridview data source</strong></p>
  <pre><code>private async void AllMusicUserControl_Load(object sender, EventArgs e)
          {
  DataTable dt = new DataTable();
              dt.Columns.Add(&quot;Songs&quot;, typeof(string));
              dt.Columns.Add(&quot;Artists&quot;, typeof(string));
              dt.Columns.Add(&quot;Duration&quot;, typeof(string));
  
              var user = await Task.Run(() =&gt;
              {
                  for (int i = 0; i &lt; ListSongInfo.Count; i++)
                  {
                      TimeSpan time = TimeSpan.FromSeconds(ListSongInfo[i].Duration);
                      dt.Rows.Add(ListSongInfo[i].Value, ListSongInfo[i].Artist, time.ToString(@&quot;mm\:ss&quot;));
                  }
                  return dt;
              });
  
              ProgressIndicator.Visible = false;
              DataGridViewAllMusic.DataSource = user;
  }
  </code></pre>