-4
success = await _myHid.SendOutputReportViaInterruptTransfer(_deviceData, _hidHandle, outputReportBuffer);
給我此錯誤錯誤
在「等待」操作符只能異步方法內使用。考慮使用「異步」修飾符標記此方法,並將其返回類型更改爲「任務」。 S:\ blissbox \ SOURCE_FILES \ Bliss-Box_api \ managed dx attempt \ BBAPI.cs 40
這裏是我的方法。
internal async Task<Boolean> SendOutputReportViaInterruptTransfer
(FileStream fileStreamDeviceData, SafeFileHandle hidHandle, Byte[] outputReportBuffer)
{
try
{
var success = false;
// Begin writing the Output report.
Task t = fileStreamDeviceData.WriteAsync(outputReportBuffer, 0, outputReportBuffer.Length);
await t;
// Gets to here only if the write operation completed before a timeout.
Debug.Print("Asynchronous write completed");
// The operation has one of these completion states:
switch (t.Status)
{
case TaskStatus.RanToCompletion:
success = true;
Debug.Print("Output report written to device");
break;
case TaskStatus.Canceled:
Debug.Print("Task canceled");
break;
case TaskStatus.Faulted:
Debug.Print("Unhandled exception");
break;
}
return success;
}
catch (Exception ex)
{
DisplayException(ModuleName, ex);
throw;
}
}
我做錯了什麼?
編譯器要求你做的方法從你也調用'SendOutputReportViaInterruptTransfer'' async'。 – dasblinkenlight
當你在你的項目中引入'async'時,你需要使'async'完成。換句話說,就像在Task.Run(async()=> {...})任務中封裝調用一樣;''你需要使所有的調用函數都是'async',並且所有的調用函數都是調用函數'async',一直在鏈上。 – lebelinoz