在实现接口时删除异步/等待警告CS1998
假设我实现了有两种方法的接口:创建
和createAsync
。在我的情况下,异步方法不是真正异步,它使用Syncronous 创建
方法返回创建对象:
public Task<GrandeurDTO> CreateAsync()
{
var dto = Create();
return Task.FromResult(dto);
}
public GrandeurDTO Create()
{
var bo = new Grandeur();
var dto = _mapper.Map<GrandeurDTO>(bo);
return dto;
}
我应该如何删除警告
这种异步方法缺乏“等待”运算符,并且会同步运行。 考虑使用“等待”操作员等待非阻止API调用, 或'等待任务。lun(CS1998)
知道我不能在create
中重命名该方法(我已经有一个;原因;如果不是一个问题,则与这个)
Suppose I implement an interface where there are two methods: Create
and CreateAsync
. The Async method in my case is not really async, and it uses the syncronous Create
method to return the created object:
public Task<GrandeurDTO> CreateAsync()
{
var dto = Create();
return Task.FromResult(dto);
}
public GrandeurDTO Create()
{
var bo = new Grandeur();
var dto = _mapper.Map<GrandeurDTO>(bo);
return dto;
}
How should I remove the warning
This async method lacks 'await' operators and will run synchronously.
Consider using the 'await' operator to await non-blocking API calls,
or 'await Task.Run(CS1998)
knowing I can't rename the method in Create
(I already have one; cause if not the question is similar to this one)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这只是一个疲倦的视觉工作室的情况,1)重新编译或2)与重新启动可以解决该问题。
I believe this is just a case of a tired Visual Studio and 1) a recompile or 2) VS restart will fix the issue.