-1
매개 변수로 메서드를 전달하려고합니다. 이 메서드는 아무 것도 반환하지 않으므로 (void) Action
형태로 처리합니다. 명령에서 Execute
을 호출 할 때 오류가 발생합니다. 이것은 오류입니다 :매개 변수로 함수 (결과 형식없이)
Can not be converted from '
void
' to 'System.Action
'.
어떤 도움이 필요합니까?
private async void Execute(Action runAction)
{
...
await TaskEx.Run(() => runAction);
...
}
_command1 = new RelayCommand(Execute(Class.ExecuteVoidMethod1()),() => CanExecuteVoidMethod1());
편집
_command1 = new RelayCommand(Execute(() => Class.ExecuteVoidMethod1()),() => CanExecuteVoidMethod1()); // Same Error
_command1 = new RelayCommand(Execute(() => Class.ExecuteVoidMethod1),() => CanExecuteVoidMethod1()); // Only assignment, call, increment, decrement, await expresion and new object expressions can be used as a statement
@ThePerplexedOne 안녕하세요, 감사합니다.하지만 반환 값이 필요할 때 Func가 사용됩니까? 이건 아니야? – avechuche
가능한 인수 유형 'void'는 'System.Action'매개 변수 유형에 할당 할 수 없습니다.] (http://stackoverflow.com/questions/3387812/argument-type-void-is-not-assignable-to-parameter -type-system-action) –
'TaskEx.Run (() => runAction())'또는'TaskEx.Run (runAction)'만 사용해야합니다. 현재'Func'을 전달 중입니다. –
Lee