This project has moved. For the latest updates, please go here.

Canceling a scan through code

Oct 17, 2016 at 8:30 PM
I am trying to get the user settings for a scan from the UI, and then keep these but set my own compression based on the bit depth of the image.

In order to accomplish this I am simply saving the settings from a scan on the xfer setup event and then I want to cancel the scan, and start a new one using the settings I want. I know this is convoluted but its the only thing I have come up with that supports compression for color and black and white images.

However, I have not been able to find a way to cancel a scan. I tried closing the data source but it has not been effective at canceling.
Coordinator
Oct 18, 2016 at 7:18 PM
Hello, ghostbust555.
private void _twain32_SetupMemXferEvent(object sender,Twain32.SetupMemXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
private void _twain32_MemXferEvent(object sender,Twain32.MemXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
private void _twain32_SetupFileXferEvent(object sender,Twain32.SetupFileXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
private void _twain32_FileXferEvent(object sender,Twain32.FileXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
private void _twain32_EndXfer(object sender,Twain32.EndXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
private void _twain32_XferDone(object sender,Twain32.XferDoneEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
Marked as answer by SARAFF on 10/22/2016 at 1:34 PM
Oct 18, 2016 at 8:25 PM
So I am not seeing the cancel property. Looking at the code I only see FileName and am getting Cancel not found on the filexfereventargs object.
public sealed class SetupFileXferEventArgs:EventArgs {

            /// <summary>
            /// Инициализирует новый экземпляр класса <see cref="SetupFileXferEventArgs"/>.
            /// </summary>
            internal SetupFileXferEventArgs() {
            }

            /// <summary>
            /// Возвращает или устанавливает имя файла изображения.
            /// </summary>
            public string FileName {
                get;
                set;
            }
        }
Coordinator
Oct 19, 2016 at 7:21 AM
Hello, ghostbust555.
Obviously, you need to update to the latest version.