c# - Progress bar does not updated wpf? -


this question has answer here:

i trying update progress bar inside contentrendered(object sender, eventargs e) event. code :-

mainwindow.xaml.cs

dynamiccontrols.progressbarwindow _progressbarwindow = new dynamiccontrols.progressbarwindow("please wait..."); _progressbarwindow.showdialog(); 

xaml

<window x:class="nk_image_converter.dynamiccontrols.progressbarwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="progressbarwindow" height="100" width="500" borderthickness="0" windowstyle="none" resizemode="noresize" background="#d4dce6" loaded="window_loaded" initialized="window_initialized" contentrendered="window_contentrendered" layoutupdated="window_layoutupdated" activated="window_activated" > <window.effect>     <dropshadoweffect opacity="0.4"/> </window.effect> <border borderbrush="cadetblue" borderthickness="3,0,3,3">     <grid>         <grid.rowdefinitions>             <rowdefinition height="20"/>             <rowdefinition height="*"/>         </grid.rowdefinitions>         <grid grid.row="0" background="cadetblue"></grid>         <grid grid.row="1" background="transparent">             <label x:name="message" content="please wait..." margin="42,15"/>             <progressbar x:name="progressbar" width="400" height="25" margin="47,38,47,14" foreground="cadetblue" borderbrush="cadetblue" borderthickness="2"></progressbar>         </grid>     </grid> </border> 

nk_image_converter.dynamiccontrols.progressbarwindow

c#

private void window_contentrendered(object sender, eventargs e)     {         for(//some condition//)         {               stuff               thread.sleep(100);               this.progressbar.value = //some value               // above statement doesn't update progressbar instantly          }     } 

in code above, want progress bar move give value every time inside loop, gets updated when event completed.

you can use backroundworker update value of progress bar below:

private void window_contentrendered(object sender, eventargs e) {     backgroundworker worker = new backgroundworker();     worker.workerreportsprogress = true;     worker.dowork += new doworkeventhandler(worker_dowork);     worker.runworkerasync(); }   private void worker_dowork(object sender, doworkeventargs e) {     backgroundworker worker = sender backgroundworker;      for(//some condition//)     {           //some stuff           thread.sleep(100);           worker.reportprogress(/*some value*/);      } } 

backroundworker in system.componentmodel.backgroundworker namespace.

additional information can found here.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -