Twain driver crashes, requiring restart of WIA...?
Twain driver crashes, requiring restart of WIA...?
I was having a problem where if my program errored out, the twain driver wouldn't work until I rebooted. The problem was caused by not closing the twain driver before exiting. Not a graceful recovery at all. However, I found that instead of having to reboot, I could fix the problem by restarting the WIA service.
A twain driver is not a WIA driver, why is it required to either reboot or restart the WIA service if you exit without closing the twain driver? That doesn't make any sense, and it makes for extremely fragile code that is not robust.
A twain driver is not a WIA driver, why is it required to either reboot or restart the WIA service if you exit without closing the twain driver? That doesn't make any sense, and it makes for extremely fragile code that is not robust.
Re: Twain driver crashes, requiring restart of WIA...?
Hmmm.... Now restarting the WIA service doesn't work anymore, only rebooting does...
Re: Twain driver crashes, requiring restart of WIA...?
Hi,
The first thing to do is to try to avoid crash from your application.
Also, I suggest you to close the device source each time you don't need to use it.
Only your application can close an opened source. This can be done using one of the TwainCloseSource(), TwainCloseSourceManager() or TwainUnloadSourceManager() methods or releasing from memory the GdTwain object.
Loïc
The first thing to do is to try to avoid crash from your application.
Also, I suggest you to close the device source each time you don't need to use it.
Only your application can close an opened source. This can be done using one of the TwainCloseSource(), TwainCloseSourceManager() or TwainUnloadSourceManager() methods or releasing from memory the GdTwain object.
Loïc
Re: Twain driver crashes, requiring restart of WIA...?
Yes, I have a try / catch block around the areas where it needs to be open, so I'm only getting the problem if I terminate execution while stopped at a breakpoint in the debugger.
However, if you know an error can be generated, there is always the distinct possibility that it might pop-up at some other time, and so it is always a good idea to have a special catch case for that possibility, if it can be dealt with. Even if the resetting of the WIA service doesn't work 100% time, if it works even some of the time I think it is better to try that out before letting the program bomb.
Why does it stay stuck until you reboot? Isn't there some other way to reset the state of the driver?
However, if you know an error can be generated, there is always the distinct possibility that it might pop-up at some other time, and so it is always a good idea to have a special catch case for that possibility, if it can be dealt with. Even if the resetting of the WIA service doesn't work 100% time, if it works even some of the time I think it is better to try that out before letting the program bomb.
Why does it stay stuck until you reboot? Isn't there some other way to reset the state of the driver?
Re: Twain driver crashes, requiring restart of WIA...?
Hi,
Regards,
Loïc
Like I said before, if you open the source you need to close it yourself using the methods I gave you or releasing the gdtwain objects from the memory.Why does it stay stuck until you reboot?
I think it is an unfortunate behaviour of the WIA layer. I can only suggest you to try to unplug and plug again your device or to use the TWAIN driver of it.Why does it stay stuck until you reboot? Isn't there some other way to reset the state of the driver?
Regards,
Loïc
Re: Twain driver crashes, requiring restart of WIA...?
The code listed below will restart the WIA service. I've tested it a dozen times now by terminating execution in the debugger without letting it go to the exception catch. The vast majority of the time it works great. However, I'm still getting a msgbox, directly from the driver I suspect, that says the scanner can't be accessed: "Communication failed. Make sure the power is on, the cable is firmly connected, etc..."
Is there any way to shut that dialog box off? It stops execution.
Private Sub RestartWIAService()
Dim Service As ServiceProcess.ServiceController = Nothing
Try
Dim serviceDisplayName As String = "Windows Image Acquisition (WIA)" 'Display Name
Dim services As ServiceProcess.ServiceController() = ServiceProcess.ServiceController.GetServices()
For Each Service In services
If Service.DisplayName = serviceDisplayName Then
Exit For
End If
Next Service
Catch ex As Exception
MsgBox("Error while intitialising scanner driver." & vbCrLf & "Cannot enumerate the services.")
End Try
Try
If Not Service Is Nothing Then
If Service.CanStop AndAlso (Not Service.Status = ServiceProcess.ServiceControllerStatus.Stopped) Then
Service.Stop()
Service.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)
End If
Service.Start()
Service.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running)
End If
Catch ex As Exception
MsgBox("Error while intitialising scanner driver." & vbCrLf & "Unable to restart Windows Image Acquisition (WIA) service.")
End Try
End Sub
Is there any way to shut that dialog box off? It stops execution.
Private Sub RestartWIAService()
Dim Service As ServiceProcess.ServiceController = Nothing
Try
Dim serviceDisplayName As String = "Windows Image Acquisition (WIA)" 'Display Name
Dim services As ServiceProcess.ServiceController() = ServiceProcess.ServiceController.GetServices()
For Each Service In services
If Service.DisplayName = serviceDisplayName Then
Exit For
End If
Next Service
Catch ex As Exception
MsgBox("Error while intitialising scanner driver." & vbCrLf & "Cannot enumerate the services.")
End Try
Try
If Not Service Is Nothing Then
If Service.CanStop AndAlso (Not Service.Status = ServiceProcess.ServiceControllerStatus.Stopped) Then
Service.Stop()
Service.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)
End If
Service.Start()
Service.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running)
End If
Catch ex As Exception
MsgBox("Error while intitialising scanner driver." & vbCrLf & "Unable to restart Windows Image Acquisition (WIA) service.")
End Try
End Sub
Who is online
Users browsing this forum: No registered users and 1 guest