Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Responsive WPF UI

Posted on 2014-01-22
Medium Priority
Last Modified: 2014-02-18
I ahve a WPF application not implementing any mVVM.
I have  button click event, where I would like to show a progress Image, and then start a background thread to get some data.
In the background thread when the data has ben retrieved, I want to hide the Progress image.

  private void Button_Click(object sender, RoutedEventArgs e)
            //imgProgress.Visibility = System.Windows.Visibility.Visible;
            Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                    imgProgress.Visibility = System.Windows.Visibility.Visible;

 public void StartBackgroundThread()
            BackgroundWorker bgWorker = new BackgroundWorker();
            bgWorker.WorkerSupportsCancellation = true;
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);          

        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
            BackgroundWorker bgWork = (BackgroundWorker)sender;
            if ((bgWork.CancellationPending == true)) { e.Cancel = true; }

 void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
imgProgress.Visibility = System.Windows.Visibility.Hidden;

THE UI freezes when the data retrival takes a long time, so does the Progress image.
Question by:countrymeister
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 23

Expert Comment

ID: 39802027
Try making bgWorker a private class variable instead of local.  This will prevent it from being GC, which might be causing the behavior you described.

Accepted Solution

countrymeister earned 0 total points
ID: 39806864
Tried that but it did not help

Author Closing Comment

ID: 39866902
Please close this question, no expert helped

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question