oledb - Database loading progress in C# -
i working on application loads ole database datagridview. although database file locally stored, takes time application load databse, "loading" cursor. want more: want create progress bar show while db loading , hide when db loaded.
i searched on google, not find looking for. can do?
(i working in visual studio, keep in mind whole code dataset automatically written ide)
you looking backgroundworker used in conjunction progressbar put both on form , use following code:
public partial class form1 : form { public form1() { initializecomponent(); shown += new eventhandler(form1_shown); // report progress background worker need set property backgroundworker1.workerreportsprogress = true; // event raised on worker thread when worker starts backgroundworker1.dowork += new doworkeventhandler(backgroundworker1_dowork); // event raised when call reportprogress backgroundworker1.progresschanged += new progresschangedeventhandler(backgroundworker1_progresschanged); } void form1_shown(object sender, eventargs e) { // start background worker backgroundworker1.runworkerasync(); } // on worker thread our thing! void backgroundworker1_dowork(object sender, doworkeventargs e) { // background task goes here (int = 0; <= 100; i++) { // report progress 'ui' thread backgroundworker1.reportprogress(i); // simulate long task system.threading.thread.sleep(100); } } // on 'ui' thread can update progress bar void backgroundworker1_progresschanged(object sender, progresschangedeventargs e) { // progress percentage property of e progressbar1.value = e.progresspercentage; }
}
this example of how use it. need modify the:
backgroundworker1.reportprogress(i);
so reporting progress pertaining happening ole database.
Comments
Post a Comment