有时候实现一些接口类的全部方法,某些方法里必须返回一个task,创建一个新任务又怕开销太大,搜了一下,发现下面是一个比较常见的做法
return Task.FromResult(null);
如果用DotNet 4.6的话,就更简单了,直接返回Task.CompletedTask就可以了。
https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.completedtask.aspx
有时候实现一些接口类的全部方法,某些方法里必须返回一个task,创建一个新任务又怕开销太大,搜了一下,发现下面是一个比较常见的做法
return Task.FromResult(null);
如果用DotNet 4.6的话,就更简单了,直接返回Task.CompletedTask就可以了。
https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.completedtask.aspx
You must be logged in to post a comment.
Hey There. I found your blog using msn. This is a very well written article.
I’ll be sure to bookmark it and return to read more of your useful info.
Thanks for the post. I will certainly comeback.
Hi! Do you know if they make any plugins to safeguard against hackers?
I’m kinda paranoid about losing everything I’ve worked hard on. Any
tips?
You could definitely see your enthusiasm in the work you write.
The arena hopes for more passionate writers like you who aren’t
afraid to say how they believe. At all times follow your heart.