Can anyone tell me if there is any underlying difference between these 2 lines of code. I'm thinking there is or I would expect VS would suggest removing unneeded keywords. I don't understand what the difference is though and when is the proper time to use them. Both ways seem to work the same in my application but I'd like to be consistent and do what's best in this situation.
For this example I am getting a DataTable from the database to use as a data source for a drop down list. It's called from a synchronous UI function.
MyDropdown.DataSource = Task.Run(async () => await GetDataTableAsync(filter)).Result; MyDropdown.DataSource = Task.Run(() => GetDataTableAsync(filter)).Result; Thanks
Task.Result-call, which will block your thread. Apart from this your two lines are identical.async void ...and then you can be async down the line without that kind of trouble.MyDropdown.DataSource = GetDataTableAsync(filter).Result;?GetDataTableAsyncfails with multiple exceptions. In this rare case the async/await version will suppress all exceptions apart from the first. On the contrary the async/await-eliding version will propagate all exceptions.