-
Notifications
You must be signed in to change notification settings - Fork 8
/
MainWindow.xaml.cs
42 lines (37 loc) · 1.15 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.IO;
using System.Windows;
namespace ThreadAffinity;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void findButton_Click(object sender, RoutedEventArgs e)
{
SynchronizationContext uiContext = SynchronizationContext.Current!;
Task.Run(() =>
{
string pictures =
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
var folder = new DirectoryInfo(pictures);
FileInfo[] allFiles =
folder.GetFiles("*.jpg", SearchOption.AllDirectories);
FileInfo? largest =
allFiles.OrderByDescending(f => f.Length).FirstOrDefault();
if (largest is not null)
{
uiContext.Post(_ =>
{
long sizeMB = largest.Length / (1024 * 1024);
outputTextBox.Text =
$"Largest file ({sizeMB}MB) is {largest.FullName}";
},
null);
}
});
}
}