-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingWindow.xaml.cs
More file actions
40 lines (34 loc) · 1.07 KB
/
Copy pathLoadingWindow.xaml.cs
File metadata and controls
40 lines (34 loc) · 1.07 KB
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
using System.Windows;
using System.ComponentModel;
namespace PdfEater;
public partial class LoadingWindow : Window {
private int taskCount;
private Action<int> taskFunction;
public LoadingWindow(Action<int> taskFunction, int taskCount) {
this.taskFunction = taskFunction;
this.taskCount = taskCount;
InitializeComponent();
}
private void Window_ContentRendered(object sender, EventArgs e) {
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += worker_DoWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerAsync();
worker.RunWorkerCompleted +=
(s, eArgs) => this.Close();
}
void worker_DoWork(object? sender, DoWorkEventArgs e) {
for(int i = 0; i < taskCount; i++) {
if (sender is not null) {
BackgroundWorker? senderWorker = sender as BackgroundWorker;
if (senderWorker is not null)
senderWorker.ReportProgress(i);
}
taskFunction(i);
}
}
void worker_ProgressChanged(object? sender, ProgressChangedEventArgs e) {
progressBar.Value = e.ProgressPercentage;
}
}