ookii-dialogs / ookii-dialogs-wpf

Awesome dialogs for Windows Desktop applications built with Microsoft .NET (WPF)
BSD 3-Clause "New" or "Revised" License
1.14k stars 85 forks source link

Added CancellationTokenSource to ProgressDialog #54

Closed vpenades closed 3 years ago

vpenades commented 3 years ago

Also Added IServiceProvider to ProgressDialog, so we can retrieve CancellationTokenSource from 'Sender' event argument.

CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.

augustoproiete commented 3 years ago

LMK when it's ready for review again

vpenades commented 3 years ago

I've considered adding the cancellationToken to the Show / ShowDialog but there's quite a lot of methods like these, are you sure you want to add the CancellationToken to every one of these methods?

augustoproiete commented 3 years ago

Yes... Because calling Show or ShowDialog causes the background worker to run, I see that as a "job", and each job could have its own CancellationToken, so having it as an argument for Show / ShowDialog seems like a good direction to go. The lifecycle of the CancellationTokenSource linked would also match the job execution lifecycle.

My initial thinking was to add new overloads (rather than include the CancellationToken with a default value) so that it doesn't break anyone that get the package transitively, but I'm also happy to release this as a major version.

So either:

Ookii.Dialogs.Wpf v3.2.0

Show()
+Show(CancellationToken cancellationToken)

Show(object argument)
+Show(object argument, CancellationToken cancellationToken)

ShowDialog()
+ShowDialog(CancellationToken cancellationToken)

ShowDialog(Window owner)
+ShowDialog(Window owner, CancellationToken cancellationToken)

ShowDialog(IntPtr owner)
+ShowDialog(IntPtr owner, CancellationToken cancellationToken)

ShowDialog(Window owner, object argument)
+ShowDialog(Window owner, object argument, CancellationToken cancellationToken)

ShowDialog(IntPtr owner, object argument)
+ShowDialog(IntPtr owner, object argument, CancellationToken cancellationToken)

or

Ookii.Dialogs.Wpf v4.0.0

-Show()
+Show(CancellationToken cancellationToken = default)

-Show(object argument)
+Show(object argument, CancellationToken cancellationToken = default)

-ShowDialog()
+ShowDialog(CancellationToken cancellationToken = default)

-ShowDialog(Window owner)
+ShowDialog(Window owner, CancellationToken cancellationToken = default)

-ShowDialog(IntPtr owner)
+ShowDialog(IntPtr owner, CancellationToken cancellationToken = default)

-ShowDialog(Window owner, object argument)
+ShowDialog(Window owner, object argument, CancellationToken cancellationToken = default)

-ShowDialog(IntPtr owner, object argument)
+ShowDialog(IntPtr owner, object argument, CancellationToken cancellationToken = default)
augustoproiete commented 3 years ago

@vpenades your changes have been merged, thanks for your contribution :+1: