Avatar ·

async/await: when to return Task and when void in C#?

Hello, colleagues! I started learning asynchronous programming in C# and ran into some confusion. I'm using .NET 4.5, writing a WPF application. When I make a method asynchronous using the async keyword, I don't always understand which return type to choose: Task or void? For example, I have a button that loads data: ```csharp private async void Button_Click(object sender, RoutedEventArgs e) { await LoadDataAsync(); } ``` It seems to work. But I've seen that in some examples they write `async Task` instead of `async void`. What's the difference? And why does the compiler sometimes complain if I try to make an `async void` method that is not an event handler? I also tried to make a method that just waits: ```csharp public async void WaitAndLog() { await Task.Delay( ```