Generally, in .NET, I run time-consuming things asynchronously so I do not catch the visual thread . In a simple example, if I have a loading in the UI, in case slow things run without awaited , they catch that loading , which was executed in thread visual.
Actions that may be time-consuming, such as processing a list, loops or reading files, I execute asynchronously. But when I have things I know are not time-consuming, like a simple conditional structure:
public bool? ToBoolean(int input)
{
if (input == 1)
{
return true;
}
else if (input == 0)
{
return false;
}
return null;
}
For these cases, which I know are fast (in theory), should I have something of the type?
public async Task<bool?> ToBooleanAsync(int input)
{
return await Task.Run(() => ToBoolean(input));
}
Should I execute fast things asynchronously, and why (or why not)?