diff --git a/src/NTwain/Internals/ITwainSessionInternal.cs b/src/NTwain/Internals/ITwainSessionInternal.cs index 9655c21..1cc1a59 100644 --- a/src/NTwain/Internals/ITwainSessionInternal.cs +++ b/src/NTwain/Internals/ITwainSessionInternal.cs @@ -41,6 +41,7 @@ namespace NTwain.Internals ReturnCode DisableSource(); void SafeSyncableRaiseEvent(DataTransferredEventArgs e); + void SafeSyncableRaiseEvent(TransferCanceledEventArgs e); void SafeSyncableRaiseEvent(TransferErrorEventArgs e); void SafeSyncableRaiseEvent(TransferReadyEventArgs e); diff --git a/src/NTwain/Internals/TransferLogic.cs b/src/NTwain/Internals/TransferLogic.cs index dcbafd2..dfa6f4d 100644 --- a/src/NTwain/Internals/TransferLogic.cs +++ b/src/NTwain/Internals/TransferLogic.cs @@ -145,9 +145,11 @@ namespace NTwain.Internals { case ReturnCode.Success: case ReturnCode.XferDone: - case ReturnCode.Cancel: // ok to keep going break; + case ReturnCode.Cancel: + session.SafeSyncableRaiseEvent(new TransferCanceledEventArgs()); + break; default: var status = session.CurrentSource.GetStatus(); session.SafeSyncableRaiseEvent(new TransferErrorEventArgs(rc, status)); diff --git a/src/NTwain/TransferCanceledEventArgs.cs b/src/NTwain/TransferCanceledEventArgs.cs new file mode 100644 index 0000000..c745ab4 --- /dev/null +++ b/src/NTwain/TransferCanceledEventArgs.cs @@ -0,0 +1,17 @@ +using System; + +namespace NTwain +{ + /// + /// Indicates a transfer cancellation, e.g. if the user pressed the "Cancel" button. + /// + public class TransferCanceledEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + public TransferCanceledEventArgs() + { + } + } +} diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainSession.cs index f71af1e..e8744f9 100644 --- a/src/NTwain/TwainSession.cs +++ b/src/NTwain/TwainSession.cs @@ -482,6 +482,10 @@ namespace NTwain /// public event EventHandler DataTransferred; /// + /// Occurs when a transfer was canceled. + /// + public event EventHandler TransferCanceled; + /// /// Occurs when an error has been encountered during transfer. /// public event EventHandler TransferError; @@ -680,6 +684,12 @@ namespace NTwain /// The instance containing the event data. protected virtual void OnDataTransferred(DataTransferredEventArgs e) { } + /// + /// Called when a transfer was canceled. + /// + /// The instance containing the event data. + protected virtual void OnTransferCanceled(TransferCanceledEventArgs e) { } + /// /// Called when an error has been encountered during transfer. /// diff --git a/src/NTwain/TwainSessionInternal.cs b/src/NTwain/TwainSessionInternal.cs index e20876b..5528f8f 100644 --- a/src/NTwain/TwainSessionInternal.cs +++ b/src/NTwain/TwainSessionInternal.cs @@ -96,6 +96,10 @@ namespace NTwain { SafeSyncableRaiseOnEvent(OnDataTransferred, DataTransferred, e); } + void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferCanceledEventArgs e) + { + SafeSyncableRaiseOnEvent(OnTransferCanceled, TransferCanceled, e); + } void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferErrorEventArgs e) { SafeSyncableRaiseOnEvent(OnTransferError, TransferError, e);