The await operator can only be used within an async method

后端 未结 2 441
生来不讨喜
生来不讨喜 2021-01-29 14:24

I have an interface ISFactory as follows.

namespace MyApp.ViewModels
{
    public interface IStreamFactory
    {
        Stream CreateSPStream(strin         


        
2条回答
  •  情歌与酒
    2021-01-29 15:07

    The best approach is to make the method async, as the compiler error indicates:

    public async Task CreateSerialPortStreamAsync(string serialPortName)
    

    This will require the interface to change as well:

    Task CreateSerialPortStreamAsync(string serialPortName);
    

    And yes, all callers of this method will need to be updated.

提交回复
热议问题