Skip to content

Commit

Permalink
fixed huge lag while searching for an asset by delaying the textchang…
Browse files Browse the repository at this point in the history
…ed event, you have 600 milliseconds before it checks your text and search for the asset
  • Loading branch information
AsvalGTA committed Apr 24, 2019
1 parent adffecf commit 6f6b7cf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
29 changes: 29 additions & 0 deletions FModel/Custom/TypeAssistant.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 14 additions & 4 deletions FModel/Forms/SearchFiles.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FModel.Custom;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f6b7cf

Please sign in to comment.