Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can display a progress bar while data is loading from database using Entity Framework?

What I have tried:

i try to using Backgroungworker but failed :(
Posted
Updated 27-Dec-18 0:29am
Comments
Maciej Los 27-Dec-18 6:14am    
What have you tried?

1 solution

If you want to show a progress bar while a long task it going on, then you need to do the long process in a second thread, and update the progress control in the "normal" UI thread - as you cannot access any control from a thread other than the UI thread (and you will get a "Cross threading exception" if you try).
Normally, the BackgroundWorker is ideal for this, as it provides a progress update mechanism via an event which is handled on the original thread and allows you to update the progress control directly.

But ... unless your data is being loaded via a SqlDataReader when you can update progress regularly it's not going to help. If you use a DataAdapter - and EF does - then there is no "progress" indication: all the work is done at the Server end, and the Client (your app) is only made aware of the data when it is all complete: it's a monolithic process.

Your best bet is to use a BackgroundWorker (or a Thread directly) or the UI won't update at all, and use a ProgressBar in Marquee mode.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900