Running on Empty

The few things I know, I like to share.

WPF ProgressBar and Long Running Processes


Often during long running processes it is useful to indicate in the UI that the process is running.  Rather than simply locking the UI from the user it is preferable to display a progressbar.  In my current implementation I have a server side process that I know takes a maximum of 30 seconds to complete.  So when I call this process from the UI, I display a progressbar that is timed to reach it’s maximum at 30 seconds.

The ProgressBar Window

<Windown ...>

      <ProgressBar x:Name="MessageProgessBar"
                   Maximum="100" Minimum="0"
                   Height="25" Width="275">
          <EventTrigger RoutedEvent="ProgressBar.Loaded">
                <DoubleAnimation Storyboard.TargetName="MessageProgessBar"
                                 From="0" To="100" Duration="0:0:30"/>

Calling Long Running Processes

//Open the Progressbar Window.
ThreadStart ts = delegate
 Dispatcher.BeginInvoke(DispatcherPriority.Normal, (EventHandler)
         // Do Cleanup Process HERE!               
        }, null, null);
ts.BeginInvoke(null, null);

Thank you Linda for your comments and reminder of subjects I have yet to post.

Please feel free to leave comments or suggestions.

January 23, 2009 Posted by | C#, WPF, XAML | 4 Comments