0

I have wpf application with button on it.

The click event of the button start process take for approximately 30-50 sec. I want to use progress bar while this thread is working. out of this i try also dispatcher.invoke. no success.

this is my code:

MainWindow.xaml.cs:

 public MainWindow()
    {
      some code.....
      Engine.ProgressEvent += (percent) => Dispatcher.Invoke(new Action(() => progressBarIndicator.Value = percent));
      some code...

    }
    private void btnFirmwareUpdate_Click(object sender, RoutedEventArgs e)
    {
      some code...
      send data to hardware using functions in Engine class
      Engine e = new Engine();
      e.update();
    }

my Engine.cs :

Class Engine 
{
    public static event Action<double> ProgressEvent;

    public update()
    {

      ProgressEvent(10);
    }
}

the progress bar indeed get the update the progress bar in the correct value but the gui is not refreshing. solutions any one?

Natile
  • 193
  • 1
  • 6
  • 20

1 Answers1

2

I suggest use a BackgroundWorker to update your Main UI.

Here is an example of how to implement a progress bar using a BackgroundWorker

Progress bar

MRebai
  • 5,344
  • 3
  • 33
  • 52