Skip to content

Commit 3018e5a

Browse files
Merge pull request #56 from ookii-dialogs/add-progress-dialog-do-work-event-args
Add ProgressDialogDoWorkEventArgs extension (non-breaking)
1 parent 7ad03d0 commit 3018e5a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Ookii.Dialogs.Wpf/ProgressDialog.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Runtime.InteropServices;
2323
using System.Windows;
2424
using System.Windows.Interop;
25+
using System.Threading;
2526

2627
namespace Ookii.Dialogs.Wpf
2728
{
@@ -679,8 +680,19 @@ public void ReportProgress(int percentProgress, string text, string description,
679680
protected virtual void OnDoWork(DoWorkEventArgs e)
680681
{
681682
DoWorkEventHandler handler = DoWork;
682-
if( handler != null )
683-
handler(this, e);
683+
if (!(handler is null))
684+
{
685+
var eventArgs = new ProgressDialogDoWorkEventArgs(e.Argument, CancellationToken.None)
686+
{
687+
Cancel = e.Cancel,
688+
Result = e.Result,
689+
};
690+
691+
handler(this, eventArgs);
692+
693+
e.Cancel = eventArgs.Cancel;
694+
e.Result = eventArgs.Result;
695+
}
684696
}
685697

686698
/// <summary>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.ComponentModel;
2+
using System.Threading;
3+
4+
namespace Ookii.Dialogs.Wpf
5+
{
6+
/// <summary>
7+
/// Provides data for the System.ComponentModel.BackgroundWorker.DoWork event handler.
8+
/// </summary>
9+
public class ProgressDialogDoWorkEventArgs : DoWorkEventArgs
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="ProgressDialogDoWorkEventArgs"/> class.
13+
/// </summary>
14+
/// <param name="argument">Specifies an argument for an asynchronous operation.</param>
15+
/// <param name="cancellationToken">Specifies a cancellation token for an asynchronous operation.</param>
16+
public ProgressDialogDoWorkEventArgs(object argument, CancellationToken cancellationToken)
17+
: base(argument)
18+
{
19+
CancellationToken = cancellationToken;
20+
}
21+
22+
/// <summary>
23+
/// Gets a value that represents the CancellationToken of an asynchronous operation.
24+
/// </summary>
25+
public CancellationToken CancellationToken { get; }
26+
}
27+
}

0 commit comments

Comments
 (0)