how to Show progress Bar In Display While Executing Method in c# -
in application want show progress bar in display while user click on specific button,
i implemented below code
private bool importdata() { bool result = false; //thread othread = new thread(new threadstart(frmwaitshow)); try { thread backgroundthread = new thread( new threadstart(() => { //othread.start(); (int n = 0; n < 100; n++) { thread.sleep(50); progressbar1.begininvoke(new action(() => progressbar1.value = n)); } } )); backgroundthread.start(); // progress bar should start here intdevid = int.parse(cmbdevicename.selectedvalue.tostring()); fetchdevicedata(intdevid); // fetch remove device info sql database //ftptcompletedbatchtransfer(); fetchmaxreportid(); getftpfile(strdeviceip, strdeviceusername, strdevicepwd, strdevicepath + "//runningbatch//runningbatch.db", "runningbatch.db"); // copy runningbatch.db debug folder remote loadrunningdata(); // running data in dataset running.db decodebatchdata_r(); // save in batch master , row data table getftpfile(strdeviceip, strdeviceusername, strdevicepwd, strdevicepath + "//completedbatch//completedbatch.db", "completedbatch.db"); loadcompleteddata(); decodebatchdata(); result = true; // progress bar should stop here } catch (exception ex) { clslogs.logerror("error: " + ex.message + this.name + " || importdata"); result = false; } //othread.abort(); return result; }
but not showing properly.. takes time start progress bar,, start before end of these function , close within 2 secound
you can use backgroundworker
, has support progress indication.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.110).aspx
Comments
Post a Comment