Solved

C# Update Status Bar....

Posted on 2016-11-08
1
22 Views
Last Modified: 2016-11-09
I am trying to update a user control status bar with text in WPF.  This should be easy I was thinking then I am now trying it.  I understand that I am in the UI context but have issues in making the update take place.  At the end of the routine the status bar updates but that is no indicator since everything either failed or completed.

The primary issue is that there is a long winded routine based off of a click event.  So this long process runs and during the course of that, we need to have it say "Copied your email" do more stuff... "Updated your directories" ....more stuff.... "etc."

Trying [STAThread] above the method and having a background worker was useless....(still not sure why that failed).  After 100 iterations I am tired of this burning cycle and decide to ask for help.

If we can call a method UpdateStatus() which is responsive (updates the text in the status control) we are golden.

Thanks in advance!
0
Comment
Question by:cyimxtck
1 Comment
 
LVL 8

Accepted Solution

by:
Paweł earned 500 total points
Comment Utility
I'm not 100% sure of what you're getting at, however i believe that your user control which is a status bar has a property that you're trying to update. you're probably doing things asynchronously in the background and then updating this property, however since you're not using the async/await keywords you're not getting access to the UI thread when you update. so you're going to have to do your updates in a delegate try something like the following in your async method

async Task Foo(){

   await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
    //update you're status bar property here.

});
}

I think that's your issue, or something of that nature if you post a bit of your c# code, the method or function that's trying to update the UI i can probably give you a better answer, but my money is on you're trying to update the UI thread from a background thread.

http://msdn.microsoft.com/en-us/library/cc647509.aspx

//use like so
Application.Current.Dispatcher.Invoke(new Action(() => {
    // do stuff here
}));

*i'm running on 0 sleep sorry if this is a bit convoluted, but google "c# Update UI thread from background" that'll get you what you need
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now