【问题标题】:Why MODI doesn't let me delete the processed file?为什么 MODI 不让我删除处理过的文件?
【发布时间】:2010-12-31 11:13:15
【问题描述】:
private void button4_Click(object sender, EventArgs e)
{
        OCR.recognize("test1.tif");
        System.IO.File.Delete("test1.tif"); // <--- Problem on this line
}

....

public static string recognize(string filepath, MODI.MiLANGUAGES language =
MODI.MiLANGUAGES.miLANG_RUSSIAN)
{
        if (!File.Exists(filepath)) return "error 1: File does not exist";
        MODI.Document doc = new MODI.Document();
        doc.Create(filepath);

        doc.OCR(language, true, true);
        MODI.Image image = (MODI.Image)doc.Images[0];

        string result="";
        foreach (MODI.Word worditems in image.Layout.Words)
        {
            result += worditems.Text + ' ';

        // Processed image is ALWAYS a question
            if (worditems.Text[worditems.Text.Length - 1] == '?') break;
        }


        doc.Close();

        return result;

}

问题是:文件被另一个进程使用。

OCR 后如何删除?

【问题讨论】:

    标签: c# file ocr delete-file modi


    【解决方案1】:

    有人posted a solution为此:

    public void Dispose()  
    {   
            doc.Close(false); 
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);
            doc = null; 
            GC.Collect();
    }
    

    也许它也适用于您的情况。

    【讨论】:

    • 您仍然可以使用 SysInternals 的进程监视器来查看实际访问文件的进程。也许它与您目前认为的不同。 technet.microsoft.com/en-us/sysinternals/bb896645
    • 不,它是那个应用程序。 quiz.vshost.exe,其中 quiz 是我的应用程序。
    • 这修复了它:image = null; GC.Collect(); GC.WaitForPendingFinalizers();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 2019-05-30
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    相关资源
    最近更新 更多