I created an application in WPF using the MVVM template.
The application works fine in the Visual Studio debugger, but when I run exe from the debug / release folder, it becomes very slow.
Here is my class RelayCommand:
public class RelayCommand : ICommand
{
private readonly Action<object> execute;
private readonly Predicate<object> canExecute;
public RelayCommand(Action<object> execute) : this(execute, DefaultCanExecute)
{
}
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
this.execute = execute;
this.canExecute = canExecute;
}
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
bool res = false;
if (canExecute != null)
{
res = canExecute(parameter);
}
return res;
}
public void Execute(object parameter)
{
execute(parameter);
}
private static bool DefaultCanExecute(object parameter)
{
return true;
}
}
If I remove the method from my class , the exe version will work as usual. CanExcecute()RelayCommand
Please explain why this is happening. Is this for an event handler CanExecuteChanged?
source
share