// HOW-TO: Use Dispose Pattern with FlexiCapture Engine objects public static void How_to_use_Dispose_Pattern_with_FlexiCapture_Engine_objects(IEngine engine) { // The .NET languages extensively use "Dispose Pattern" to allow deterministically // manage unmanaged resources. Objects which support "disposal" implement IDispose // interface, which allows using these objects in "using" statements or correctly aggregate // them in other disposable objects. // Many ABBYY FlexiCapture Engine objects require disposal. // For example, an open project, batch or document requires closing. // One way to guarantee that these objects are always closed properly is to use try...finally // block and remember to call Close for these objects in Dispose method if aggregated (in a view). // The other way is to write wrappers around critical FlexiCapture Engine objects to better // integrate them with the language: trace("Using a wrapper implementing IDisposable for IProject..."); using (DisposableProject project = new DisposableProject(engine, SamplesFolder + "\\SampleProject\\Invoices_eng.fcproj")) { // Do some processing. The project is guaranteed to be closed on leaving this block of code // (both normally or due to an exeption being thrown). // ... project.Close(); } }
// HOW-TO: Use Dispose Pattern with FlexiCapture Engine objects public static void How_to_use_Dispose_Pattern_with_FlexiCapture_Engine_objects( IEngine engine ) { // The .NET languages extensively use "Dispose Pattern" to allow deterministically // manage unmanaged resources. Objects which support "disposal" implement IDispose // interface, which allows using these objects in "using" statements or correctly aggregate // them in other disposable objects. // Many ABBYY FlexiCapture Engine objects require disposal. // For example, an open project, batch or document requires closing. // One way to guarantee that these objects are always closed properly is to use try...finally // block and remember to call Close for these objects in Dispose method if aggregated (in a view). // The other way is to write wrappers around critical FlexiCapture Engine objects to better // integrate them with the language: trace( "Using a wrapper implementing IDisposable for IProject..." ); using( DisposableProject project = new DisposableProject( engine, SamplesFolder + "\\SampleProject\\Invoices_eng.fcproj" ) ) { // Do some processing. The project is guaranteed to be closed on leaving this block of code // (both normally or due to an exeption being thrown). // ... project.Close(); } }