Consider the following:
public class FooController : Controller
{
public async Task<ActionResult> Foo()
{
await DoSomethingAsync();
...
return View();
}
public async Task<ActionResult> Bar()
{
await DoSomethingAsync();
...
return View();
}
...
}
This line, await DoSomethingAsync(); is repeated for each action in the controller. It'd be much nicer to do something like:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
await DoSomethingAsync();
}
But, obviously, you can't run an async op in a synchronous method. I could simply force the async op to run sync, but then you end up with the thread being blocked unnecessarily. Short of running this sync, what options do I have?