-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
55 lines (51 loc) · 1.99 KB
/
Form1.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
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
namespace WorkbookProgressSample {
public partial class Form1 : Form {
CancellationTokenSource cancellationSource;
public Form1() {
InitializeComponent();
}
private async void RunCancel_Click(object sender, EventArgs e) {
if (cancellationSource != null) {
cancellationSource.Cancel();
}
else {
progressBarLoad.Value = 0;
progressBarExport.Value = 0;
btnRunCancel.Text = "Cancel";
cancellationSource = new CancellationTokenSource();
try {
using (Workbook workbook = new Workbook()) {
await workbook.LoadDocumentAsync("Document.xlsx",
cancellationSource.Token,
new Progress<int>((progress) => {
progressBarLoad.Value = progress;
progressBarLoad.Refresh();
}));
await workbook.ExportToPdfAsync("Result.pdf",
cancellationSource.Token,
new Progress<int>((progress) => {
progressBarExport.Value = progress;
progressBarExport.Refresh();
}));
}
}
catch (OperationCanceledException) {
progressBarLoad.Value = 0;
progressBarExport.Value = 0;
}
finally {
cancellationSource.Dispose();
cancellationSource = null;
btnRunCancel.Text = "Run";
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
cancellationSource?.Cancel();
}
}
}