mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Async loading item images => huge performance improvements for old machines.
This commit is contained in:
38
Wox/Converters/AsyncConverter.cs
Normal file
38
Wox/Converters/AsyncConverter.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Wox.Converters
|
||||
{
|
||||
public class AsyncTask : INotifyPropertyChanged
|
||||
{
|
||||
public AsyncTask(Func<object> valueFunc)
|
||||
{
|
||||
LoadValue(valueFunc);
|
||||
}
|
||||
|
||||
private void LoadValue(Func<object> valueFunc)
|
||||
{
|
||||
var frame = new DispatcherFrame();
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
|
||||
object returnValue =
|
||||
AsyncValue = valueFunc();
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged(this, new PropertyChangedEventArgs("AsyncValue"));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public object AsyncValue
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user