Solved

C# Update Status Bar....

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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