【发布时间】:2019-12-08 15:31:16
【问题描述】:
我收到以下错误
错误 CS4010 无法将异步 lambda 表达式转换为委托类型 “任务行动”。异步 lambda 表达式可能返回 void、Task 或 Task,它们都不能转换为 'TaskAction'
我的函数如下所示:
public async void GetLastKnownUpdateStatus(string UUIDStr, short ClientId)
{
UpdateStatusInfo x = new UpdateStatusInfo();
if (Execution.WaitForTask(async (canceltoken) => { x = await GetLastKnownUpdateStatus(UUIDStr, ClientId); return true; }) > Execution.WAIT_TIMEOUT)
{
Output.WriteLine("GetLastKnownUpdateStatus: "+ x.State.ToString());
}
}
此方法调用以下函数:
public Task<UpdateStatusInfo> GetLastKnownUpdateStatus(string uniqueUpdateID, short clientID)
{
return GetLastKnownUpdateStatus(uniqueUpdateID, clientID, null);
}
感谢任何帮助
Execution.WaitForTask 来自 Vector.CANoe.Threading 类,由 Vector 定义如下
//
// Summary:
// Executes a task in a separate thread. During the wait, the measurement and simulation
// are not blocked. Optionally returns failure after a certain timespan.
//
// Parameters:
// taskAction:
// A delegate function to execute in a separate task
//
// maxTime:
// Optional: maximum time to wait, in milliseconds.
//
// Returns:
// WAIT_TIMEOUT: if an maxTime was defined and the task did not return within maxTime
// milliseconds WAIT_ABORTED: if the measurement was stopped during task execution
// WAIT_EXCEPTION: if an exception occurred in the taskAction delegate WAIT_ILLEGAL_RESULTVALUE:
// the result provided by the task is <= 0 > 0 any positive result provided by the
// taskAction delegate (only use numbers > 0 as return values)
//
// Remarks:
// Be careful: You may not use most of the CANoe API functions in the taskAction.
// Allowed is: Modifying SystemVariables Using Output.* functions See documentation
// for details
【问题讨论】:
-
如果您重新格式化代码以避免排长队并提供minimal reproducible example,这将非常有帮助。目前我们不知道
TaskAction是什么,并且在您提供的代码中从未提及。我们也不知道Execution.WaitForTask是什么。如果没有所有相关信息,我们将无法提供帮助。
标签: c# asynchronous lambda delegates canoe