I understand the async should not use void as return type unless it is an event handler. But I have code snippet above, when I turn on warning as error in my project setting I got the error above when I compile code.
RECS0165 Asynchronous method '' should not return void
If I remove async then I get another compile error
The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
The suggested fix is to add async to the anonymous function. It is a dead lock.
Do I do something wrong here?
The steps to reproduce the issue:
- Create a blank UWP project in VS2017, it will create app,xaml and MainPage.Xaml.
Add following code in in MainPage.Xaml.cs
namespace App4 { using System; using System.Threading.Tasks; using Windows.ApplicationModel.Core; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls;
public sealed partial class MainPage : Page { private DispatcherTimer refreshTimer; public MainPage() { this.InitializeComponent(); this.refreshTimer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 30) }; refreshTimer.Tick += async (sender, e) => { await DisplayMostRecentLocationData(string.Empty); }; } private async Task DisplayMostRecentLocationData(string s) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { }); } }}

async (sender, e) =>or use anEventArgderived class fore- Nkosi