private void SetupTimer(ICharSequence s, int before, int count) //TODO Move to lib ? { if (s.Length() == 0 || before == count) { return; } if (searchTimer != null) { searchTimer.Stop(); searchTimer.Start(); return; } searchTimer = new Timer(MillsToSearch); searchTimer.Elapsed += async delegate { try { searchTimer.Close(); searchTimer = null; var suggestionsService = AndroidDependencyContainer.Instance.SuggestionsService; SuggestionsAndIds = isTeacher ? await suggestionsService.GetSuggestedGroupsAsync(s.ToString()) : await suggestionsService.GetSuggestedGroupsAsync(s.ToString()); activity.RunOnUiThread(() => { autoCompleteTextView.UpdateSuggestions(SuggestionsAndIds, activity); }); } catch (NetworkException) { activity.RunOnUiThread(() => { Toast.MakeText(activity, activity.GetString(Resource.String.no_connection_title), ToastLength.Short).Show(); }); } }; searchTimer.Start(); }