Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show progress bar when Entity Framework transfer data

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?

like image 854
mehdi lotfi Avatar asked Sep 10 '12 04:09

mehdi lotfi


2 Answers

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...

}
like image 88
CloudyMarble Avatar answered Nov 06 '22 14:11

CloudyMarble


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.

like image 27
Jigar Pandya Avatar answered Nov 06 '22 15:11

Jigar Pandya