mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
39 lines
957 B
C#
39 lines
957 B
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|