The TWAIN Session can be ended at any point. The actions to be taken depend on the state of the session.
During Data Source Selection
OpenDataSourceManager or SelectSource has previously been called to open the Data Source Manager. Call CloseSession to close the Data Source Manager and terminate the TWAIN session.
During Capability Negotiation
OpenSession has previously been called to open the Data Source Manager and Data Source. Call CloseSession to close the Data Source and Data Source Manager and terminate the TWAIN session.
During a Scanning Session
StartSession has previously been called to begin a scanning session.
The TWAIN session can be terminated during the Scanning or Scanned event by setting the Cancel parameter.