a.w.
a.w.

Reputation: 261

Not able to run BusyIndicator with BackgroundWorker in Wpf

I have two windows. My mainWindow and the window with the busyIndicator. I'm using BackgroundWorker and Dispatcher to do the work (calculation and ui) in the main window, while I want to show up the busyIndicator. But only the window shows without the busyIndicator.

        BusyIndicator_Window busy = new BusyIndicator_Window();
        busy.Show();


        BackgroundWorker worker = new BackgroundWorker();

        worker.DoWork += (o, ea) =>
        {

            Dispatcher.Invoke((Action)(() =>
                {
                    Plot.Plot_MV.startAnke(selectedFilePath, lw);

                }));
        };

        worker.RunWorkerCompleted += (o, ea) =>
        {
            busy.busyIndicator.IsBusy = false;
        };

        busy.busyIndicator.IsBusy = true;
        worker.RunWorkerAsync(); 

is there anything I got wrong? Thanks

Upvotes: 0

Views: 577

Answers (1)

nvoigt
nvoigt

Reputation: 77304

A background worker that immediately delegates back to the UI thread is pretty useless. Just do the work you want to do:

worker.DoWork += (o, ea) =>
{
  Plot.Plot_MV.startAnke(selectedFilePath, lw);
};

Upvotes: 1

Related Questions