Here's a C# async function Foo()
in which a blocking function (File.WriteAllText) is to be called.
async Task Foo()
{
File.WriteAllText(...);
}
If Foo is called by main UI thread, using Task.Run() for calling the blocking function prevents main UI thread from blocking so that UX runs fluently.
async Task Foo()
{
await Task.Run(async ()=> { File.WriteAllText(...); }).ConfigureAwait(false);
}
Question:
If Foo is called by non-UI thread(e.g. worker threads), as worker threads don't interfere with UX fluency, calling the blocking function directly is of no problem, I think.
Is my thought right? Is there any other problem I don't know yet?