I am facing one issue with Autocomplete, I want to make a autocomplete that will wait for user to enter the complete text.
Let's suppose the user types "T", it will wait 300ms before making the request. If the user types "E" within 300ms it will not hit Any API, then user types "S" and waited 300ms It should hit the API for "TES". But then user types "T" after 10ms it should cancel the previous API request of "TES" and hit the API for "TEST" and so on. I can handle the delay by Task.Delay but don't how to cancel the previous request. Also not sure if Task.Delay is a good solution or not.
private async void TextChangedEvent(System.Object sender, ItemsChangedEventArgs e)
{
var searchText = (sender as AutoComplete).Text;
await Task.Delay(TimeSpan.FromMilliseconds(3000))
.ContinueWith(async task => await GetStatus(searchText),
CancellationToken.None,
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.FromCurrentSynchronizationContext());
}