I have the following code for scanning a document using WIA with a Kodak ScanMate i1120
public static Device InitScanner(string DeviceID)
{
var deviceManager = new DeviceManager();
// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;
// Loop through the list of devices
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
{
if (deviceManager.DeviceInfos[i].DeviceID == DeviceID)
{
firstScannerAvailable = deviceManager.DeviceInfos[i];
var device = firstScannerAvailable.Connect();
return _ConnectedScanner;
}
}
return _ConnectedScanner;
}
public void ScanDocument()
{
string _DeviceID = GetDeviceID(Properties.Settings.Default.DefaultDevice);
InitScanner(_DeviceID);
if (_ConnectedScanner == null)
{
MessageBox.Show("Scanner is not turned on or connected");
Lcontinue = false;
return;
}
else
{
try
{
_item = _ConnectedScanner.Items[1] as Item;
SelectDeviceDocumentHandling(_ConnectedScanner, DeviceDocumentHandling.Feeder);
//MessageBox.Show(GetDeviceProperty(_ConnectedScanner, 3078).ToString());
_MyImage = (ImageFile)_ConnectedScanner.Items[1].Transfer();
DocCount++;
}
catch (Exception ex)
{
switch (ex.HResult)
{
case -2145320959:
Lcontinue = false;
MessageBox.Show(ex.Message + Environment.NewLine + "Unknown Error");
return;
case -2145320957:
if (DocCount == 0)
{
Lcontinue = false;
//_WaitForOperator = false;
MessageBox.Show(ex.Message + Environment.NewLine + "There is no paper in the ADF");
return;
}
else
{
Lcontinue = false;
//WaitForOperator = false;
//DocCount = 0;
}
break;
case -2145320954:
if (DocCount == 0)
{
Lcontinue = false;
//_WaitForOperator = false;
MessageBox.Show(ex.Message + Environment.NewLine + "The device is busy, Please retry");
return;
}
else
{
Lcontinue = false;
DocCount = 0;
}
break;
default:
Lcontinue = false;
MessageBox.Show("Error No : " + ex.HResult + Environment.NewLine + Environment.NewLine + ex.ToString());
return;
}
}
}
}
I have two scanners on the system, a Kyocera and the Kodak, but I only want to use the Kodak for this app.
When I try to scan with the Kodak I get error
HRESULT: 0x80070021 System.IO.FileLoadException: `The process cannot access the file because another process has locked a portion of the file.
the error happens on the following line
var device = firstScannerAvailable.Connect();
I have no other scanning applications open so I am unable to figure out what is locking the file.
Can someone see what would be causing the file lock?
User contributions licensed under CC BY-SA 3.0