|  | 
| 1 |  | -Imports System | 
|  | 1 | +Imports System | 
| 2 | 2 | Imports System.Threading | 
| 3 | 3 | Imports System.Windows.Forms | 
| 4 | 4 | Imports DevExpress.Spreadsheet | 
| 5 | 5 | 
 | 
| 6 | 6 | Namespace WorkbookProgressSample | 
| 7 |  | -	Partial Public Class Form1 | 
| 8 |  | -		Inherits Form | 
| 9 | 7 | 
 | 
| 10 |  | -		Private cancellationSource As CancellationTokenSource | 
|  | 8 | + Public Partial Class Form1 | 
|  | 9 | + Inherits Form | 
| 11 | 10 | 
 | 
| 12 |  | -		Public Sub New() | 
| 13 |  | -			InitializeComponent() | 
| 14 |  | -		End Sub | 
|  | 11 | + Private cancellationSource As CancellationTokenSource | 
| 15 | 12 | 
 | 
| 16 |  | -		Private Async Sub RunCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRunCancel.Click | 
| 17 |  | -			If Not Me.btnRunCancel.IsHandleCreated Then Return | 
|  | 13 | + Public Sub New() | 
|  | 14 | + InitializeComponent() | 
|  | 15 | + End Sub | 
| 18 | 16 | 
 | 
| 19 |  | -			If cancellationSource IsNot Nothing Then | 
| 20 |  | -				cancellationSource.Cancel() | 
| 21 |  | -			Else | 
| 22 |  | -				progressBarLoad.Value = 0 | 
| 23 |  | -				progressBarExport.Value = 0 | 
| 24 |  | -				btnRunCancel.Text = "Cancel" | 
| 25 |  | -				cancellationSource = New CancellationTokenSource() | 
| 26 |  | -				Try | 
| 27 |  | -					Using workbook As New Workbook() | 
| 28 |  | -						Await workbook.LoadDocumentAsync("Document.xlsx", cancellationSource.Token, New Progress(Of Integer)(Sub(progress) | 
| 29 |  | -							progressBarLoad.Value = progress | 
| 30 |  | -							progressBarLoad.Refresh() | 
| 31 |  | -						End Sub)) | 
| 32 |  | -						Await workbook.ExportToPdfAsync("Result.pdf", cancellationSource.Token, New Progress(Of Integer)(Sub(progress) | 
| 33 |  | -							progressBarExport.Value = progress | 
| 34 |  | -							progressBarExport.Refresh() | 
| 35 |  | -						End Sub)) | 
| 36 |  | -					End Using | 
| 37 |  | -				Catch e1 As OperationCanceledException | 
| 38 |  | -					progressBarLoad.Value = 0 | 
| 39 |  | -					progressBarExport.Value = 0 | 
| 40 |  | -				Finally | 
| 41 |  | -					cancellationSource.Dispose() | 
| 42 |  | -					cancellationSource = Nothing | 
| 43 |  | -					btnRunCancel.Text = "Run" | 
| 44 |  | -				End Try | 
| 45 |  | -			End If | 
| 46 |  | -		End Sub | 
|  | 17 | + Private Async Sub RunCancel_Click(ByVal sender As Object, ByVal e As EventArgs) | 
|  | 18 | + If cancellationSource IsNot Nothing Then | 
|  | 19 | + cancellationSource.Cancel() | 
|  | 20 | + Else | 
|  | 21 | + progressBarLoad.Value = 0 | 
|  | 22 | + progressBarExport.Value = 0 | 
|  | 23 | + btnRunCancel.Text = "Cancel" | 
|  | 24 | + cancellationSource = New CancellationTokenSource() | 
|  | 25 | + Try | 
|  | 26 | + Using workbook As Workbook = New Workbook() | 
|  | 27 | + Await workbook.LoadDocumentAsync("Document.xlsx", cancellationSource.Token, New Progress(Of Integer)(Sub(progress) | 
|  | 28 | + progressBarLoad.Value = progress | 
|  | 29 | + progressBarLoad.Refresh() | 
|  | 30 | + End Sub)) | 
|  | 31 | + Await workbook.ExportToPdfAsync("Result.pdf", cancellationSource.Token, New Progress(Of Integer)(Sub(progress) | 
|  | 32 | + progressBarExport.Value = progress | 
|  | 33 | + progressBarExport.Refresh() | 
|  | 34 | + End Sub)) | 
|  | 35 | + End Using | 
|  | 36 | + Catch __unusedOperationCanceledException1__ As OperationCanceledException | 
|  | 37 | + progressBarLoad.Value = 0 | 
|  | 38 | + progressBarExport.Value = 0 | 
|  | 39 | + Finally | 
|  | 40 | + cancellationSource.Dispose() | 
|  | 41 | + cancellationSource = Nothing | 
|  | 42 | + btnRunCancel.Text = "Run" | 
|  | 43 | + End Try | 
|  | 44 | + End If | 
|  | 45 | + End Sub | 
| 47 | 46 | 
 | 
| 48 |  | -Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)HandlesMe.FormClosing | 
| 49 |  | -cancellationSource?.Cancel() | 
| 50 |  | -End Sub | 
| 51 |  | -End Class | 
|  | 47 | +Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) | 
|  | 48 | +cancellationSource?.Cancel() | 
|  | 49 | +End Sub | 
|  | 50 | +End Class | 
| 52 | 51 | End Namespace | 
0 commit comments