我创建了一个返回字符串值的函数,但是我收到的错误是:
异步方法的返回类型必须为void,Task或Task
这是代码:
private async string SerialRead()
{
const uint maxReadLength = 1024;
DataReader dataReader = new DataReader(SerialPort.InputStream);
uint bytesToRead = await dataReader.LoadAsync(maxReadLength);
string rxBuffer = dataReader.ReadString(bytesToRead);
return rxBuffer;
}
答案 0 :(得分:2)
试试这个
private async Task<string> SerialRead()
{
const uint maxReadLength = 1024;
DataReader dataReader = new DataReader(SerialPort.InputStream);
uint bytesToRead = await dataReader.LoadAsync(maxReadLength);
string rxBuffer = dataReader.ReadString(bytesToRead);
return rxBuffer;
}