I have a project that uses data from Entity Framework
and present them in WPF
. I want show threaded progress bar when Entity Framework load/save data on presentation layer.
Can you please help me to understand how can I do that?
I found this neat example to do that using Skip
/Take
methods. Basically you load x amount of records each round, which you Skip
on the next round, and calculate this from the amount of all data in your table which enables you to update the progress bar each round.
Take a look at this:
List<MyDataTable> someData = new List<MyDataTable>();
int rowCount = dt.myDataTable.Count();
//TODO: <= display a progress bar here, and set max to rowCount...
int currentRows = 0;
while (currentRows < rowCount)
{
someData.AddRange(dt.myDataTable.Skip(currentRows).Take(10000).ToList());
currentRows = someData.Count;
//TODO: <= update progress here...
}
You can use Dispatcher Thread to achieve this; Basically you need to create a common class that is extended in other UI classes.
To achieve this you can see basic example here; more precise example and downloadable code is available here.
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