Community

FCEngine loading

I am trying to Use FCEngile in my webservice by loading the FCEngine.DLL library. Once i am rtying to load the engine its throwing an exception thet "FC Engine has to be loaded on the same thread as it was initialized". kindly advice hiw to over come the same. Please have a look the codes for your reference.

  1. Web method public void ProcessImage(byte[] document,string ImageName, string DocumentType, string DeviceId) { string serializedXML = string.Empty; try {
    if (document.Length > 1 && !string.IsNullOrEmpty(ImageName) && !string.IsNullOrEmpty(DocumentType)) { DeviceID = DeviceId; ImgName = ImageName; InitDefaults(int.Parse(DocumentType)); ImgPath = sampleCollection + DeviceId + "//" + ImageName + ".png"; DirectoryInfo dirInfo = new DirectoryInfo(sampleCollection + DeviceId); if (dirInfo.Exists == false) Directory.CreateDirectory(sampleCollection + DeviceId); if (File.Exists(ImgPath)) { File.Delete(ImgPath); FileStream fStream = new FileStream(ImgPath, FileMode.OpenOrCreate); fStream.Write(document, 0, document.Length); } else { FileStream fStream = new FileStream(ImgPath, FileMode.OpenOrCreate); fStream.Write(document, 0, document.Length); } processCurrentImageFile(); }
    } catch (Exception Exp) { if (Exp.InnerException != null) new ACRException("PowerExtractionService.ProcessImage(): " + Exp.InnerException.ToString(), ACRException.ErrorType.Error); else { new ACRException("PowerExtractionService.ProcessImage(): " + Exp.Message, ACRException.ErrorType.Error); } }
    }

  2. method process Current Image File

private void processCurrentImageFile() { try { if (engine == null) { engine = loadEngine(); } if (processor == null) { processor = engine.CreateFlexiCaptureProcessor(); processor.AddDocumentDefinitionFile(templatePath); } else { processor.ResetProcessing(); } processor.AddImageFile(ImgPath); IDocument document = processor.RecognizeNextDocument();
} catch (Exception Exp) { if (Exp.InnerException != null) new ACRException("PowerExtractionService.processCurrentImageFile(): " + Exp.InnerException.ToString(), ACRException.ErrorType.Error); else { new ACRException("PowerExtractionService.processCurrentImageFile(): " + Exp.Message, ACRException.ErrorType.Error); } } }

  1. Method Load Endgine

static IEngine loadEngine() { IEngine engine = null; try { int hresult = InitializeEngine(GetDeveloperSN(), null, null, out engine); Marshal.ThrowExceptionForHR(hresult); } catch (Exception Exp) { if (Exp.InnerException != null) new ACRException("PowerExtractionService.loadEngine(): " + Exp.InnerException.ToString(), ACRException.ErrorType.Error); else { new ACRException("PowerExtractionService.loadEngine(): " + Exp.Message, ACRException.ErrorType.Error); } } return engine; }

    public static string GetDeveloperSN()
    {

        return "xxxxxxxxxxxxxxxxxxxxxx";
    }

Was this article helpful?

0 out of 0 found this helpful

Comments

3 comments

  • Avatar
    SDK_support

    Till FCEngine 10, it was impossible to run and use Engine object in several threads, but starting from FCEngine 10 this feature becomes possible with the help of InprocLoader or OutprocLoader.

    If you use the InitializeEngine (InitializeEngineEx) function for loading, using Engine object in several threads is impossible. In this case the methods of all ABBYY FlexiCapture Engine objects should be called only from the thread in which Engine object was created.

    Please see more details of its implementation in Help → Frequently Asked Questions → Is it posssible to run and use Engine object in several threads?

    0
  • Avatar
    Hari

    Thanks for the support. We are using abbyy flexicapture engine 10.5 for OCR extraction and we need to run the same on our web service. i tried the same code for loading the engine in Winforms and it was working perfectly well and the same code in webservice giving the error. Can u please let me know the linitialization of engine by InprocLoader or OutprocLoader.

    The load constructor of IengineLoader take two paramenters. 1.serial number-is this the licese number of abbyy flexicapture engine??? 2. Appdate path--is the the dll path of FCEngine.dll???

    Kindly advice us regarding the same.

    0
  • Avatar
    SDK_support

    As the first parameter serial number of developer license to FCEngine should be passed, ans as thew second parameter you can specify path to the FlexiCapture Engine data folder, please see more details in Help → API Reference → Objects → Engine Loaders → IEngineLoader → Load method.

    0

Please sign in to leave a comment.