Re: [問題] MODI.Document 創建
Dear 各位前輩們:
小弟最近剛好有用到MODI
但一直被"MODI有時候無法release"的問題困擾很久
常常會因為這問題造成crash
就算用try catch包起來也是會crash
剛好有survey到板上這篇前輩寫的文章
我在release的寫法是:
modiDocument.Close(false);
if (modiDocument != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(modiDocument);
modiDocument = null;
}
if (modiImage != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(modiImage);
modiImage = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
但我用了之後, 在一直跑OCR的情況下
"有時候"一樣會有下列的exception:
"Attempted to read or write protected memory.
This is often an indication that other memory is corrupt."
似乎還是沒辦法完全release?
可否請前輩們指點一下
感激不盡!
※ 引述《kewang (一切都不對了~)》之銘言:
: ※ 引述《kewang (一切都不對了~)》之銘言:
: : --
: : 雜七雜八的kewang部落格 http://kewang.tw
: : --
: : ◆ From: 118.167.130.202
: : → oooandooo:http://0rz.tw/p56hf 12/05 00:15
: : → oooandooo:我在網路上有查了一下,是MODI本身的問題 12/05 00:16
: : → oooandooo:這個網址有人寫出方法把圖片跟路徑清空 12/05 00:17
: : → oooandooo:理面有提到他並沒有完全解決這個問題 12/05 00:18
: 我找了其他的資料,不知道算不算解決這個問題。
: string result = string.Empty;
: MODI.Document modiDocument = new MODI.Document();
: modiDocument.Create(filename);
: MODI.Image modiImage = (MODI.Image)modiDocument.Images[0];
: modiImage.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_TRADITIONAL, false,
: false);
: foreach (MODI.Word word in modiImage.Layout.Words) {
: result += word.Text;
: }
: modiDocument.Close(false);
: modiImage = null;
: GC.Collect();
: return result;
: 記得要讓modiImage變為null,然後再用GC強制執行回收機制,這樣就可以了。
: 原po可以試試看喔。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.87.71.10
推
11/29 00:27, , 1F
11/29 00:27, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 5 之 5 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章
13
32