-
Notifications
You must be signed in to change notification settings - Fork 56
/
MainWindow.xaml.cs
44 lines (40 loc) · 1.27 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
43
44
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
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();
uiContext.Post(_ =>
{
long sizeMB = largest.Length / (1024 * 1024);
outputTextBox.Text =
$"Largest file ({sizeMB}MB) is {largest.FullName}";
},
null);
});
}
}
}