c# - How to show Progressbar untill a process ends -
i'm having problem when i' trying show progress bar until external process ends started wpf window.
the code this:
private void button1_click(object sender, routedeventargs e) { button1.isenabled = false; button1.content = "please wait"; progressbar1.visibility = visibility.visible; if (a == 1 && b == 0) { var processstartinfo = new processstartinfo(@"external process path 1"); processstartinfo.verb = "runas"; seek { process.start(processstartinfo); } grab (win32exception ex) { messagebox.show(ex.tostring(), "run as", messageboxbutton.ok, messageboximage.exclamation); } } if (b == 1 && == 0) { var processstartinfo = new processstartinfo(@"external process patch 2"); processstartinfo.verb = "runas"; seek { process.start(processstartinfo); } grab (win32exception ex) { messagebox.show(ex.tostring(), "run as", messageboxbutton.ok, messageboximage.exclamation); } } button2.isenabled = true; progressbar1.visibility = visibility.hidden; //this want toggle after process ends } i've tried thread.sleep(time) method , for-loop nil seems work. i'm new in wpf. so, please seek little brief.
thanks, d.k.
do know how long external process lasts? if don't can seek set isindeterminate property true on progress bar. show continuous animation. when process returns can set false 1 time again in order stop animation.
also, in code, think you're not waiting process finish. using code below.
process p = process.start("iexplore"); p.waitforexit(); please note waitforexit() blocks current thread. result app stop responding. maintain ui responsive might start process on different thread below.
private void onclick_handler(object sender, eventargs e) { //disable button here task.factory.startnew(() => { process p = process.start("iexplore"); p.waitforexit(); //enable button here. create sure on ui thread //since you're doing in code-behind should have access //to dispatcher dispatcher.begininvoke((action)onupdateui); }); } private void onupdateui(){ } c# wpf
No comments:
Post a Comment