If you want an anonymous method, you will have to declare the one that returns Task<Session> , since it is marked with the async modifier, so it should return void (only for async event handlers), Task or Task<T> :
Func<Task<Session>> anonFunction = async () => await fileService.ReadJsonAsync();
If everything you do is launched by ReadJsonAsync , you can also save yourself the generation of state apparatus as follows:
Func<Task<Session>> anonFunction = fileService.ReadJsonAsync;
Then you can await on it with a higher order:
Func<Task<Session>> anonFunction = fileService.ReadJsonAsync; await anonFunction();
Yuval Itzchakov
source share