2016-12-01 1 views
-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 
+0

@ThePerplexedOne 안녕하세요, 감사합니다.하지만 반환 값이 필요할 때 Func가 사용됩니까? 이건 아니야? – avechuche

+0

가능한 인수 유형 'void'는 'System.Action'매개 변수 유형에 할당 할 수 없습니다.] (http://stackoverflow.com/questions/3387812/argument-type-void-is-not-assignable-to-parameter -type-system-action) –

+3

'TaskEx.Run (() => runAction())'또는'TaskEx.Run (runAction)'만 사용해야합니다. 현재'Func '을 전달 중입니다. – Lee

답변

0

왜 당신은 Execute 방법에 작업을 호출하지 않습니다?

await TaskEx.Run(() => runAction); 

당신은 다음과 같이 실행해야합니다 : 다른 경우

await TaskEx.Run(() => runAction()); 

당신이 그것을 실행하는 대신 액션을 반환한다.

관련 문제