0

I have a method that use async/await:

    private async void Start_Click(object sender, EventArgs e)
    {
        await M1Async();
    }

    static async Task M1Async()
    {
        await M2Async();
    }

    static async Task M2Async()
    {
        await M3Async();
    }

    static async Task M3Async()
    {
        await M4Async();
    }

    static async Task M4Async()
    {
        // start download using async scenario
        await StaryDownloadAsync();
    }

What will be a good practice in this case ? should I decorate all Methods with async/await or just the method that do the actual async scenario ?

Thanks in advance.

Khayralla
  • 177
  • 1
  • 4
  • 15

1 Answers1

0

Depends on your actual scenario, but it would be much simple to do as following:

private async void Start_Click(object sender, EventArgs e)
{
    await M1Async();
}

private static Task M1Async()
{
    return M2Async();
}

private static Task M2Async()
{
    return M3Async();
}

private static Task M3Async()
{
    return M4Async();
}

private static Task M4Async()
{
    return Task.Delay(1000);
}
ken2k
  • 48,145
  • 10
  • 116
  • 176
  • So the last method (M4Async) should decorated with async and I have to add await to call the StaryDownloadAsync method ! – Khayralla Jun 20 '14 at 15:18