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

Cancelling ProgressDialog can cause NullReferenceException #138

Closed ptsoccer closed 1 year ago

ptsoccer commented 1 year ago

There's some sort of race condition where if you press the cancel button on the progress dialog and then dispose it, a null reference exception will occur in _backgroundWorker_ProgressChanged where it tries to cancel the field, _cancellationTokenSource.

https://github.com/ookii-dialogs/ookii-dialogs-wpf/blob/9addd3ff1d35e1a006b8bea0ac8d98462924e2a5/src/Ookii.Dialogs.Wpf/ProgressDialog.cs#L849-L857

In this case, cancellationRequestedByUser is true, but _cancellationTokenSource is null since the dispose method in ProgressDialog sets it to null. I think the obvious solution here is to just to a null safe call on Cancel, especially since in line 852 it's already doing it.