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)));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With