public bool CanExecute(object parameter = null) { try { return(canExecute != null?canExecute() : executingCount == 0); } catch (Exception ex) { XLog.Trace(ex); return(true); } }
public async void Execute(object parameter = null) { bool couldExecuteBeforeExecute = CanExecute(); if (!couldExecuteBeforeExecute) { return; } Interlocked.Increment(ref executingCount); bool couldExecuteDuringExecute = CanExecute(); if (couldExecuteDuringExecute != couldExecuteBeforeExecute) { RaiseCanExecuteChanged(); } try { if (execute != null) { execute(); } else { await asyncExecute(); } } catch (Exception ex) { XLog.Trace(ex); } finally { Interlocked.Decrement(ref executingCount); bool couldExecuteAfterExecute = CanExecute(); if (couldExecuteAfterExecute != couldExecuteDuringExecute) { RaiseCanExecuteChanged(); } } }