This method contains a bunch of Redis code, and is called in many places and is part of a deep method call stack:
public void Save()
{
Task.Run(async () =>
{
var transaction = cache.CreateTransaction();
var _ = transaction.StringSetAsync();
_ = transaction.SetAddAsync();
await transaction.ExecuteAsync();
}).Wait();
}
I understand a thread pool thread will be used to do this work, and that the calling thread will be blocked via the Wait()
call, and will be unable to take any more ASP.NET requests as it waits for the Redis code to finish.
Would this blocking be insignificant enough to warrant keeping the code how it is to avoid having to update the signature of all the methods that call this code to include async
/await
?
Also, because only transaction.ExecuteAsync()
is await
ed in the delegate, could transaction.ExecuteAsync()
be run before the Task
s above it had completed?