避免
async void。让您的方法返回
Task而不是
void。然后,您可以使用
await它们。
像这样:
private async Task RequestToSendOutputReport(List<byte[]> byteArrays){ foreach (byte[] b in byteArrays) { while (condition) { // we'll typically execute this pre many times until the condition is no longer met Task t = SendOutputReportViaInterruptTransfer(); await t; } // read some data from device; we need to wait for this to return await RequestToGetInputReport(); }}private async Task RequestToGetInputReport(){ // lots of pre prior to this int bytesRead = await GetInputReportViaInterruptTransfer();}


