I am trying to postpone the processing of the method (SubmitQuery () in the example) called from a keyboard event in WinRT until there are no events for a period of time (in this case there will be 500 ms).
I want the SubmitQuery () function to run when I think the user has finished typing.
Using the following code, I keep getting System.Threading.Tasks.TaskCanceledException when Task.Delay (500, cancelationToken.Token); called. What am I doing wrong here, please?
CancellationTokenSource cancellationToken = new CancellationTokenSource(); private async void SearchBox_QueryChanged(SearchBox sender, SearchBoxQueryChangedEventArgs args) { cancellationToken.Cancel(); cancellationToken = new CancellationTokenSource(); await Task.Delay(500, cancellationToken.Token); if (!cancellationToken.IsCancellationRequested) { await ViewModel.SubmitQuery(); } }
c # asynchronous windows-runtime cancellationtokensource
Andrew Roberts
source share