首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么MODI不让我删除已处理的文件?

为什么MODI不让我删除已处理的文件?
EN

Stack Overflow用户
提问于 2010-12-31 19:13:16
回答 1查看 1.1K关注 0票数 1
代码语言:javascript
复制
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后如何删除?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-31 19:17:34

有人对此执行posted a solution

代码语言:javascript
复制
public void Dispose()  
{   
        doc.Close(false); 
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);
        doc = null; 
        GC.Collect();
}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4569728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档