How can I make label display cpu load Real time data

I know how to get cpu load value using performance counter but have no idea how to make a label display it in real time

Answers


Bind your label content to your ViewModel:

XAML (YourView.xaml.cs):

<Label Content="{Binding CPUText}" />

Your View Model would look like this:

public class YourViewModel : INotifyPropertyChanged
{

  public void GetCpuText()
  {
     //your code here.... 
     //it would populate your CPUText property...

     CPUText = .... (your code to get the cpu info)
  }
  private _cpuText;

  public string CPUText
  {
     get
     {
        return _cpuText;
     }
     set
     {
        _cpuText = value;

         NotifyPropertyChanged("CPUText");
     }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected void NotifyPropertyChanged(String info) {
    if (PropertyChanged != null) {
        PropertyChanged(this, new PropertyChangedEventArgs(info));
    }
  }
}

An example to make this work is to create your view, set the DataContext of that view to your ViewModel class:

var view = new YourView();
view.DataContext = new YourViewModel();
view.GetCpuText();

Need Your Help

WPF Using commands to slow to update UI controls

wpf button command performance

I bind a command to a button through command property and doing a command binding in the page it is placed. In execute method I create an instance of a class that contains the background worker and I

Is it possible to bubble a MouseEvent by z-index instead of hierarchy?

actionscript-3 flex ilog-elixir

I have two components being absolutely positioned within a container (they are MapSymbols on an ILOG Elixir map, if that helps). Each component is a VBox with an Image and a Label. Images have