c# - my Gridview still freezes in backgroundworker Dowork while using this.invoke(MethodInvoker)delegate -
i want update gridview gradually while retrieving data
i've backgroundworker work function follows
private void backgroundwrkr_dowork(object sender, doworkeventargs e) { datatable dtinstant = new datatable(); (int = 0; < allfiles.count; i++) { if (backgroundwrkr.cancellationpending) { e.cancel = true; return; } myapp.processfile(allfiles[i]); this.invoke((methodinvoker)delegate { mygrdvw.datasource = myapp.dtresults; }); backgroundwrkr.reportprogress(100 * (i + 1) / allfiles.count); } backgroundwrkr.reportprogress(100); }
and report progress function
private void backgroundwrkr_progresschanged(object sender, progresschangedeventargs e) { progressbar.value = e.progresspercentage; }
and backgroundwrkr complete
private void backgroundwrkr_runworkercompleted(object sender, runworkercompletedeventargs e) { progressbar.visible = false; allfiles.clear(); }
i've tried begininvoke instead of invoke , still gridview freezes! logic of proccessing files has no problem because in case put datagridview binding in workercomplete binds successfully
after 2 days of search , unsuccessful trials i've solved follows while binding seems backgroundworker working in datatable bind copy of results datatable , solves problem
private void backgroundwrkr_dowork(object sender, doworkeventargs e) { datatable dtinstant = new datatable(); (int = 0; < allfiles.count; i++) { if (backgroundwrkr.cancellationpending) { e.cancel = true; return; } myapp.processfile(allfiles[i]); this.invoke((methodinvoker)delegate { mygrdvw.datasource = myapp.dtresults.copy(); }); backgroundwrkr.reportprogress(100 * (i + 1) / allfiles.count); } backgroundwrkr.reportprogress(100); }
thanks help!
Comments
Post a Comment