Any difference between “await Task.Run(); return;” and “return Task.Run()”?

后端 未结 4 1128
日久生厌
日久生厌 2020-11-22 01:59

Is there any conceptual difference between the following two pieces of code:

async Task TestAsync() 
{
    await Task.Run(() => DoSomeWork());
}
         


        
4条回答
  •  广开言路
    2020-11-22 03:03

    What is the difference between

    async Task TestAsync() 
    {
        await Task.Delay(1000);
    }
    

    and

    Task TestAsync() 
    {
        return Task.Delay(1000);
    }
    

    ?

    I am confused by this question. Let me try to clarify by responding to your question with another question. What's the difference between?

    Func MakeFunction()
    {
        Func f = ()=>1;
        return ()=>f();
    }
    

    and

    Func MakeFunction()
    {
        return ()=>1;
    }
    

    ?

    Whatever the difference between my two things is, the same difference is between your two things.

提交回复
热议问题