fixed huge lag while searching for an asset by delaying the textchanged event, you have 600 milliseconds before it checks your text and search for the asset

This commit is contained in:
AsvalGTA 2019-04-24 23:01:13 +02:00
parent adffecf298
commit 6f6b7cfcd2
3 changed files with 44 additions and 4 deletions

View File

@ -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);
}
}
}

View File

@ -63,6 +63,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Converter\UnrealEngineDataToOGG.cs" />
<Compile Include="Custom\TypeAssistant.cs" />
<Compile Include="Forms\About.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -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<FileInfo> myInfos = new List<FileInfo>();
List<FileInfoFilter> myFilteredInfos;
private static string fileName;
@ -25,6 +27,9 @@ namespace FModel.Forms
public SearchFiles()
{
InitializeComponent();
assistant = new TypeAssistant();
assistant.Idled += assistant_Idled;
}
private async void SearchFiles_Load(object sender, EventArgs e)
@ -255,12 +260,17 @@ namespace FModel.Forms
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)