I have a windows forms application which creates a background thread to search in files and adds matching file names to a DataGridView. Background thread uses BeginInvoke to add rows to the DataGridView and everything works fine if the background thread does not return thousands of results. The UI works perfectly fine even if the background thread processes thousands of files, unless it tries to a a few thousands of rows to the DataGridView.
I tried adding rows one by one, and buffering them and adding 100 rows at once. But the application UI become nonresponsive all the time. The background process works faster than the UI thread and there are always new rows to add to the DataGridView.
I even tried Application.DoEvents (in the UI thread) but it did not help either.
Any ideas? Can I fix it without adding a delay to the background thread?
Thanks in advance