mirror of
https://github.com/4sval/FModel.git
synced 2026-06-22 16:00:17 -05:00
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:
parent
adffecf298
commit
6f6b7cfcd2
29
FModel/Custom/TypeAssistant.cs
Normal file
29
FModel/Custom/TypeAssistant.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user