Check if TIF file in use

G

Guest

Hi,

Here is my problem. I need to check if scanner finished scanning the
document. I'm using scanner interface that came with the scanner.

I tried to open file and catch IO Exception for "The process cannot access
the file
....., because it is being used by another process." It worked with .PDF but
not with TIF files. It will allow me to open file while scanning.

Any suggestions ????

Thanks

Val
 
H

Herfried K. Wagner [MVP]

ValK said:
Here is my problem. I need to check if scanner finished scanning the
document. I'm using scanner interface that came with the scanner.

I tried to open file and catch IO Exception for "The process cannot access
the file
...., because it is being used by another process." It worked with .PDF
but
not with TIF files. It will allow me to open file while scanning.

How are you attempting to open the TIF file? You could try to open a file
stream (class 'FileStream') with appropriate share mode set and construct a
'Bitmap' object from this stream. Note that it's necessary to keep the
stream open as long as the bitmap object exists.
 
G

Guest

Jeff,

I'm not sure if I understand your question. Scanner interface it just a
program thet comes with the scanner. It seems like it doesn't put handle on
the file.
 
G

Guest

Hi Herfried,
I'm using FileStream. This is my code example:

Dim fileObj As New System.IO.FileStream(sFile, FileMode.OpenOrCreate,
FileAccess.Write, FileShare.None)
 
H

Herfried K. Wagner [MVP]

ValK said:
I'm using FileStream. This is my code example:

Dim fileObj As New System.IO.FileStream(sFile, FileMode.OpenOrCreate,
FileAccess.Write, FileShare.None)

Use 'FileShare.ReadWrite'. The value of this parameter determines which
operations /other processes/ can perform while your application is accessing
the file.
 
H

Herfried K. Wagner [MVP]

ValK said:
I just tried that too. Didn't work. Still can open file while the scanning.

Is it possible to open the file with another application such an image
viewer/editor while it is being accessed by the scanner?
 
J

Jeff Dillon

No, I mean, there isn't something you can call, to see if the job is
complete? When you say interface, is it a com or .NET object? Or just an exe
that you launch.

Like

do while not scannerObject.Complete
wait
loop

Now process the file...

Jeff
 
G

Guest

Jeff,
1) It's stand alone application (exe), user interface. User can select
available scanner, file format, dpi, scanning directory
2) How would I know "The scanner program is done" :)
 
J

Jeff Dillon

I thought you meant "programmatic interface", not "user interface".

What type of scanner is it? If HP, there are programmatic interfaces
available.

So how are you currently retrieving the file name and directory to where the
user is placing the file?

Jeff
 
A

Andrew Morton

ValK said:
Here is my problem. I need to check if scanner finished scanning the
document. I'm using scanner interface that came with the scanner.

I tried to open file and catch IO Exception for "The process cannot
access the file
...., because it is being used by another process." It worked with
.PDF but not with TIF files. It will allow me to open file while
scanning.

You could monitor the file size and when it hasn't increased for n seconds
then assume the scanning is done. Now your problem is changed to determining
a suitable value for n.

Or you could read the start of the TIF file until you find the marker/data
part which tells you how much image data there is and then you can calculate
the final size and wait until the file has reached that size.

Andrew
 
G

Guest

Andrew,
This is exactly how I have done. But this will slow down my process a big
time. Some times we have over 500 files in scanning directory.
It just drives me crazy… Why everything works the way it should with PDF but
not TIF?

Here is my function: I give 6 seconds pause

Private Function isFileInUse(ByVal sFile As String) As Boolean

Try
Dim fi As System.IO.FileInfo
Dim nLastSize As Long
Dim nNewSize As Long

fi = New System.IO.FileInfo(sFile)


fi.Refresh()
nLastSize = fi.Length
Thread.Sleep(6000)
fi.Refresh()
nNewSize = fi.Length

If nLastSize <> nNewSize Then
Return True
Else
Return False
End If

fi = Nothing

Catch ex As Exception
Throw
End Try

End Function
 
G

Guest

It's Canon DR9080C. It comes with scanning software "Capture Perfect".
"Capture Perfect" program allow user to name file, choose resolution and so
on.
All users will scan files to the same directory(c:\temp). My service
monitoring c:\temp for incoming files and process them. Scanning format TIF
and PDF only
 
A

Andrew Morton

ValK said:
Andrew,
This is exactly how I have done. But this will slow down my process a
big time.

In that case, use the second method I suggested.
big time. Some times we have over 500 files in scanning directory.

Do you mean you have 500 scanners running at the same time? If you only have
one document being scanned at a time then you can process all but the one
with the newest file date, then inspect that last file.

Have you asked Canon for help?
It just drives me crazy. Why everything works the way it should with
PDF but not TIF?

Because you want to work with TIFFs. If you /wanted/ to work with PDF files,
they would stop working ;-)

Andrew
 
G

Guest

We may have more than one document at the same time. Let's say client has 10
scanners and they all scanning to the same shared directory, monitoring by
our service. I have to grab file, check if scanning complete and process the
file. If file still in scanning, then skip file and go to the next one.

I guess the best solution would be to write our own scanner user interface
and control files from there(keep file open untill its done, or shoot the
trigger file with the same name, but different extention to the same
directory after its done). :) I'm not sure if company will go with this
approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top