diff --git a/FModel/Custom/TypeAssistant.cs b/FModel/Custom/TypeAssistant.cs new file mode 100644 index 00000000..7c597465 --- /dev/null +++ b/FModel/Custom/TypeAssistant.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace FModel.Custom +{ + public class TypeAssistant + { + public event EventHandler Idled = delegate { }; + public int WaitingMilliSeconds { get; set; } + System.Threading.Timer waitingTimer; + + public TypeAssistant(int waitingMilliSeconds = 600) + { + WaitingMilliSeconds = waitingMilliSeconds; + waitingTimer = new Timer(p => + { + Idled(this, EventArgs.Empty); + }); + } + public void TextChanged() + { + waitingTimer.Change(WaitingMilliSeconds, System.Threading.Timeout.Infinite); + } + } +} diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index b2a12015..407ca3ec 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -63,6 +63,7 @@ + Form diff --git a/FModel/Forms/SearchFiles.cs b/FModel/Forms/SearchFiles.cs index 6a977b97..3518b1ef 100644 --- a/FModel/Forms/SearchFiles.cs +++ b/FModel/Forms/SearchFiles.cs @@ -1,4 +1,5 @@ -using System; +using FModel.Custom; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; @@ -14,6 +15,7 @@ namespace FModel.Forms { public partial class SearchFiles : Form { + TypeAssistant assistant; List myInfos = new List(); List myFilteredInfos; private static string fileName; @@ -25,6 +27,9 @@ public partial class SearchFiles : Form public SearchFiles() { InitializeComponent(); + + assistant = new TypeAssistant(); + assistant.Idled += assistant_Idled; } private async void SearchFiles_Load(object sender, EventArgs e) @@ -255,12 +260,17 @@ private void filterListView() listView1.EndUpdate(); } - private async void textBox1_TextChanged(object sender, EventArgs e) + void assistant_Idled(object sender, EventArgs e) { - await Task.Run(() => + this.Invoke( + new MethodInvoker(() => { filterListView(); - }); + })); + } + private void textBox1_TextChanged(object sender, EventArgs e) + { + assistant.TextChanged(); } private void button1_Click(object sender, EventArgs e)