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

x
?
Solved

C# Update Status Bar....

Posted on 2016-11-08
1
Medium Priority
?
76 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

661 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