Skip to main content
Kofax

Implement parallel processing for an Import Module

3019324

Question / Problem: 

Is there a way to implement parallel processing for an Import Module?

Answer / Solution: 

Yes. Kofax Capture APIs are not thread safe, however it is possible to use the ThreadLocal class to implement a new login for each thread, so that imports are being performed in a thread safe manner.

    Sub Main()
        Dim oImportLogin As New Threading.ThreadLocal(Of Kofax.AscentCaptureModule.ImportLogin)(
            Function()
                Dim oLogin As New Kofax.AscentCaptureModule.ImportLogin
                oLogin.Login("", "")
                Return oLogin
            End Function, True)
        Parallel.ForEach(IO.Directory.GetFiles("path\to\files", "*.tif"),
                         Sub(s As String)
                             oImportLogin.Value.ActiveApplication.CreateBatch(oImportLogin.Value.ActiveApplication.BatchClasses("Order Forms"), Guid.NewGuid.ToString)
                             oImportLogin.Value.ActiveApplication.ActiveBatch.ImportFile(s)
                             oImportLogin.Value.ActiveApplication.CloseBatch()
                         End Sub)

        For Each o In oImportLogin.Values
            o.Logout()
            Runtime.InteropServices.Marshal.ReleaseComObject(o)
        Next
    End Sub

 

Applies to:  

Product Version
Capture 10.0
  10.1
  10.2
  11.0