如果我问一个愚蠢的问题,请原谅我。我正在处理Task.I有一个代码如下:
private string result;
public string Result
{
get { return result; }
set
{
if (value != result)
{
result = value;
OnRaise("Result");
}
}
}
的ICommand:
private ICommand _cmd;
public ICommand Cmd
{
get
{
_cmd = _cmd ?? new RelayCommand(s => RunAction(), () => IsEnable);
return _cmd;
}
}
方法和任务:
int count = 0;
private async void RunAcion()
{
IsEnable = false;
var context = TaskScheduler.FromCurrentSynchronizationContext();
await Task.Run(() => Runcmd()).ContinueWith(s => this.Result = count.ToString(), context);
IsEnable = true;
}
void Runcmd()
{
Thread.Sleep(2000);
count++;
}
MainWindow.xaml:
<Button x:Name="btnStart" Content="Start"
Height="50" IsEnabled="{Binding IsEnable}"
Command="{Binding Cmd, Delay=1000}"
/>
<TextBlock Foreground="#4C4C4C" Text="{Binding Show}"/>
运行时获得50%的CPU。如何降低CPU使用率?