Thread management

G

Guest

Hello,

I’m using a multithreaded windows service to listen a file directory and
process TIF documents.
For example if user drops 3 files to the directory,
“fileSystemWatcher_Created†event will create 3 threads.
Each thread has to process the same function.

1. Decompress file
2. Read text data from the TIF image (I’m are using “LEAD Technologies OCR
componentâ€
3. Create new document record in database

For each call to rasterOcr.StartUp() there must be a call to the
RasterOcr.ShutDown method.
Now I run into problem. My first thread didn’t finish process and didn’t
call RasterOcr.ShutDown method, but the second one trying to call StartUp.

What should I do? How can I manage them. Please point me to the right
direction.

To read data from the image I’m doing something like this.

Public Shared Function ScanFaxImage(ByVal path As String) As String
Dim rasterOcr As New rasterOcr
Dim codecs As RasterCodecs
Dim rasterImage As IRasterImage
Dim recognizedChars() As RasterOcrRecognizedCharacters

RasterSupport.Unlock(RasterSupportType.Ocr, _
ApolloScanSettings.OCRSupportKey)

rasterOcr.StartUp()

codecs = LoadCodecs()
rasterImage = codecs.Load(path)

'Add the cover sheet of the fax
rasterOcr.AddPage(rasterImage, 0)
rasterOcr.AutoOrientPage(0)
rasterOcr.EnableZoneForceSingleColumn = True
rasterOcr.ShowZoneGridLines = False

'Automatically find zones
rasterOcr.FindZones(0)

'Scan the image for recognize characters and return result

rasterOcr.ShutDown()
End Function
 
B

Brian Gideon

ValK,

Why are you calling RasterSupport.Unlock in the ScanFaxImage method?
That method gets executed several times right? I have no idea how this
OCR component works so I might be way off base, but do you really need
to make that call over and over again?

The rasterOcr variable is local to the method so each thread running
ScanFaxImage will be using a different instance. It shouldn't matter
that the first thread didn't call ShutDown on its own instance because
the second thread is using a completely different instance. Is there a
problem with the second thread calling StartUp?

Also, why are using multiple threads? Is it not easier to just process
the files serially?

Brian
 

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