Detect disabled or unpowered Devices using WIA

16 Views Asked by At

I am using the WIA library for a vb.net application to get the list of scanner devices. I need only the available devices so I can connect to then and see if they have ADF capabilities or other properties.

For Each info As DeviceInfo In manager.DeviceInfos
    If (info.Type = WiaDeviceType.ScannerDeviceType) Then
        Dim dv as Device = info.Connect()
    End If
Next

If the device is not powered the Connect() method hangs for 20 seconds.

I've tried calling the method on a separate thread using BackgroundWorker Class. My idea was to call the Connect method on all the scanners, wait 1 seconds and only use the MyScanDvClass that have the Connected property set to true. The problem is that it blocks the UI until all the background workers complete execution.

 Public Class MyScanDvClass
     Public Property dv As Device
     Public Property Connected As Boolean = False
 End Class

 Private lst_scc = New List(Of MyScanDvClass)
 Public Sub InitiateScanners()
     Dim manager As New DeviceManagerClass
     For Each info As DeviceInfo In manager.DeviceInfos
         If (info.Type = WiaDeviceType.ScannerDeviceType) Then
             Dim bw As New BackgroundWorker
             Dim sdc As New MyScanDvClass
             AddHandler bw.DoWork, Sub(sender As Object, e As DoWorkEventArgs)
                                       Dim local_sdc As MyScanDvClass = e.Argument
                                       Try
                                           local_sdc.dv = info.Connect()
                                       Catch ex As Exception
                                       End Try
                                       local_sdc.Connected = True
                                       e.Result = local_sdc
                                   End Sub

             bw.RunWorkerAsync(sdc)
         End If
     Next
 End Sub

My project is on .NET 3.5 so I don't have a lot of alternative librarys.

0

There are 0 best solutions below