From 44fe5af4fb4dfa6adb71daf7715e9ec95b313e8f Mon Sep 17 00:00:00 2001 From: kspearrin Date: Mon, 24 Sep 2018 15:45:36 -0400 Subject: [PATCH] run on main thread fixes --- src/iOS.Autofill/LoginSearchViewController.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/iOS.Autofill/LoginSearchViewController.cs b/src/iOS.Autofill/LoginSearchViewController.cs index b033a4ad2..8bcc35a09 100644 --- a/src/iOS.Autofill/LoginSearchViewController.cs +++ b/src/iOS.Autofill/LoginSearchViewController.cs @@ -174,26 +174,30 @@ namespace Bit.iOS.Autofill public override void TextChanged(UISearchBar searchBar, string searchText) { var cts = new CancellationTokenSource(); - Task.Run(async () => + Task.Run(() => { - if(!string.IsNullOrWhiteSpace(searchText)) + NSRunLoop.Main.BeginInvokeOnMainThread(async () => { - await Task.Delay(300); - if(searchText != searchBar.Text) + if (!string.IsNullOrWhiteSpace(searchText)) { - return; + await Task.Delay(300); + if (searchText != searchBar.Text) + { + return; + } + else + { + _filterResultsCancellationTokenSource?.Cancel(); + } } - else + try { - _filterResultsCancellationTokenSource?.Cancel(); + ((TableSource)_controller.TableView.Source).FilterResults(searchText, cts.Token); + _controller.TableView.ReloadData(); } - } - try - { - ((TableSource)_controller.TableView.Source).FilterResults(searchText, cts.Token); - _controller.TableView.ReloadData(); - } - catch(OperationCanceledException) { } + catch (OperationCanceledException) { } + _filterResultsCancellationTokenSource = cts; + }); }, cts.Token); } }