Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • If you don't await anything, your code should compile fine - it just won't actually be asynchronous. That may be okay if in your case there's basically a fast implementation that doesn't perform any IO - but otherwise you should really be doing things asynchronously... Commented Oct 6, 2016 at 11:01
  • If I do so I get a warning while compiling: "Async method lacks 'await' operators and will run synchronously". Why do I get this warning? Why does it matter? Commented Oct 6, 2016 at 11:11
  • Well the warning speaks for itself - you've got an async method, but it completes synchronously. In your case, that may be what you desire. It's hard to tell without knowing what the body of the CreateAsync method does. If it's always quick, then that's fine, and you can just suppress the warning for that bit of code. Commented Oct 6, 2016 at 11:13
  • Let's see if i get it right. In my case i would want to write the following code: public Task CreateAsync(AuthenticationTokenCreateContext context) { return Task.FromResult(0); } Because it is not asyncronous? Commented Oct 6, 2016 at 11:22
  • You could do, if you didn't actually want to do anything asynchronous. But we don't know whether running all your code synchronously is appropriate, because we don't know what that code is. And as hvd mentions in comments, that wouldn't work well in terms of exception handling - an async method would normally return a faulted task rather than throwing an exception, apart from possibly argument validation. Commented Oct 6, 2016 at 11:33