I'm loading in a datagrid view some data (1,200,000 rows), And the App is taking too much time to load and sometimes freezes.
I don't know how to load them asynchronously ? (with progressBar maybe).
Can I find some help here ?
I'm loading in a datagrid view some data (1,200,000 rows), And the App is taking too much time to load and sometimes freezes.
I don't know how to load them asynchronously ? (with progressBar maybe).
Can I find some help here ?
I have an application in which I'm doing something very similar using Threading. This code should update your datagrid one line at a time while the code behind is running.
using System.Windows.Threading;
private void Run()
{
try
{
var t = new Thread(Read) { IsBackground = true };
t.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Read()
{
foreach (/* whatever you are looping through */)
{
/* I recommend creating a class for the result use that for the
datagrid filling. */
var sr = new ResultClass()
/* do all you code to generate your results */
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(ThreadStart)(() => dgResults.AddItem(sr)));
}
}
Break up the data loading into smaller chunks, say 100 to 1000 rows at a time. If the WPF grid is databound to your data collection, and the collection is an observable collection (implements INotifyCollectionChanged), WPF will auto update the display as new data is added to the collection.
You should also consider using virtualized list controls or grids in conjunction with paging data sources, so that only the data that is currently shown on the screen will be loaded (instead of 1.2 million rows of data in memory). This will perform the "chunking" for you and will enable you to present basically an infinite amount of data to the user with very little memory use or network lag.
Check out this SO article on retrieving data asynchronously for a virtual listbox: How do I populate a ListView in virtual mode asynchronously?