VintaSoft Twain .NET SDK 15.0: Documentation for .NET developer
Vintasoft.WpfTwain Namespace / Device Class / AsyncEvents Property
Syntax Exceptions Remarks Example Requirements SeeAlso
In This Topic
    AsyncEvents Property (Device)
    In This Topic
    Gets or sets an array with asynchronous events which the application wants the device to report.
    Syntax
    'Declaration
    
    Public Property AsyncEvents As DeviceEventId[]
    
    
    public DeviceEventId[] AsyncEvents { get; set; }
    
    
    public: __property DeviceEventId[] get_AsyncEvents();
    public: __property void set_AsyncEvents(
    DeviceEventId[]* value
    );
    public:
    property DeviceEventId[] AsyncEvents { DeviceEventId[] get(); void set(array<DeviceEventId>^ value); }
    Exceptions
    ExceptionDescription
    Thrown if device is in wrong state.
    Thrown if device does not support capability.
    Thrown if the .NET debugger is used and the function evaluation requires all threads to run.
    Remarks

    Call this property only when device is opened (State == DeviceState.Opened).

    Supported events IDs can be received by the GetSupportedAsyncEvents method.

    Example

    This C#/VB.NET code shows how to detect when paper is jammed.

    
    ''' <summary>
    ''' Detects the paper jamm.
    ''' </summary>
    Public Sub DetectPaperJam(device As Vintasoft.Twain.Device)
            ' disable device UI
            device.ShowUI = False
            ' disable device when images are acquired
            device.DisableAfterAcquire = True
    
            ' open the device
            device.Open()
    
            ' set device settings
            device.PixelType = Vintasoft.Twain.PixelType.RGB
            device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches
            device.Resolution = New Vintasoft.Twain.Resolution(300F, 300F)
    
            Try
                    ' get events supported by device
                    Dim supportedDeviceEvents As Vintasoft.Twain.DeviceEventId() = device.GetSupportedAsyncEvents()
                    ' for each supported event
                    For i As Integer = 0 To supportedDeviceEvents.Length - 1
                            ' if device can report when paper is jammed
                            If supportedDeviceEvents(i) = Vintasoft.Twain.DeviceEventId.PaperJam Then
                                    ' specify that device must report when paper is jammed
                                    device.AsyncEvents = New Vintasoft.Twain.DeviceEventId() {Vintasoft.Twain.DeviceEventId.PaperJam}
    
                                    ' subscribe to the device event
                                    AddHandler device.AsyncEvent, New System.EventHandler(Of Vintasoft.Twain.DeviceAsyncEventArgs)(AddressOf device_DeviceEvent)
    
                                    Exit For
                            End If
                    Next
            Catch ex As System.Exception
                    System.Console.WriteLine(ex.ToString())
            End Try
    
            ' subscribe to the Device.ImageAcquired, Device.ScanCompleted, ... events
            '...
    
            ' acquire images from device
            device.Acquire()
    End Sub
    
    ''' <summary>
    ''' Occurred the device event.
    ''' </summary>
    Private Sub device_DeviceEvent(sender As Object, e As Vintasoft.Twain.DeviceAsyncEventArgs)
            System.Console.WriteLine("Paper is jammed.")
    End Sub
    
    
    
    /// <summary>
    /// Detects the paper jamm.
    /// </summary>
    public void DetectPaperJam(Vintasoft.Twain.Device device)
    {
        // disable device UI
        device.ShowUI = false;
        // disable device when images are acquired
        device.DisableAfterAcquire = true;
    
        // open the device
        device.Open();
    
        // set device settings
        device.PixelType = Vintasoft.Twain.PixelType.RGB;
        device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches;
        device.Resolution = new Vintasoft.Twain.Resolution(300f, 300f);
    
        try
        {
            // get events supported by device
            Vintasoft.Twain.DeviceEventId[] supportedDeviceEvents = device.GetSupportedAsyncEvents();
            // for each supported event
            for (int i = 0; i < supportedDeviceEvents.Length; i++)
            {
                // if device can report when paper is jammed
                if (supportedDeviceEvents[i] == Vintasoft.Twain.DeviceEventId.PaperJam)
                {
                    // specify that device must report when paper is jammed
                    device.AsyncEvents = new Vintasoft.Twain.DeviceEventId[] { Vintasoft.Twain.DeviceEventId.PaperJam };
    
                    // subscribe to the device event
                    device.AsyncEvent += new System.EventHandler<Vintasoft.Twain.DeviceAsyncEventArgs>(device_DeviceEvent);
    
                    break;
                }
            }
        }
        catch (System.Exception ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    
        // subscribe to the Device.ImageAcquired, Device.ScanCompleted, ... events
        //...
    
        // acquire images from device
        device.Acquire();
    }
    
    /// <summary>
    /// Occurred the device event.
    /// </summary>
    private void device_DeviceEvent(object sender, Vintasoft.Twain.DeviceAsyncEventArgs e)
    {
        System.Console.WriteLine("Paper is jammed.");
    }
    
    

    Requirements

    Target Platforms: .NET 8, .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also