Solved

C# Update Status Bar....

Posted on 2016-11-08
1
34 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 9

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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