From the msdn,
You can use Task.Run to move CPU-bound work to a background thread.
My question is, are there any other options? If I want to use await
keyword I must return Task and so I must use Task.Run
public static Task<int> LongProcess()
{
return Task.Run<int>(() =>
{
//Long running
return 5;
});
}
public async static void CallProcess()
{
int a = await LongProcess();
}
Isn't above code only option to use await? If not, could you please show other options? If I don't use Task.Run, why do I need async/await?