Solved

C# Update Status Bar....

Posted on 2016-11-08
1
68 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
[X]
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
1 Comment
 
LVL 10

Accepted Solution

by:
Paweł earned 500 total points
ID: 41879573
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

634 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