場景:我編寫了一個應用程序來打開.msg文件列表(已轉儲到文件系統),抓取從他們的一些信息(主題,到CC),然後移動它們。無法移動文件:進程無法訪問該文件,因爲它正在被另一個進程使用
問題:然而,當涉及到移動我得到以下錯誤文件:
The process cannot access the file because it is being used by another process.
運行處理有關文件只顯示我寫的工具,並沒有其他的手柄。
因此,我假設我在完成將它們用作Redemption MessageItem對象時沒有正確地釋放這些文件。
但是我無法將它們包裝在using語句中,因爲它們沒有實現IDisposable。而且他們不公開任何公開的關閉或處置或類似命名的方法。
總之,我試圖問:
一)我怎麼能強迫我的C#應用程序關閉一個給定的手柄,只知道路徑文件句柄?
或者
二)有沒有辦法來強制贖回對象關閉?
var util = new MAPIUtilsClass();
MessageItem item = util.GetItemFromMsgFile(EmailPath, false);
item.Import(EmailPath, 3);
Subject = item.Subject;
From = (item.SenderName.Length < 96) ? item.SenderName : item.SenderName.Substring(0, 93) + "...";
To = (String.IsNullOrEmpty(item.To)) ? String.Empty : (item.To.Length < 96) ? item.To : item.To.Substring(0, 93) + "...";
CC = (String.IsNullOrEmpty(item.CC)) ? String.Empty : (item.CC.Length < 96) ? item.CC : item.CC.Substring(0, 93) + "...";
Sent = item.SentOn;
Received = item.ReceivedTime;
Log.Write("Redemption: Email data harvested" + EmailPath);
沒有代碼,你覺得我們可以幫你嗎?! –
剛剛添加的代碼 – Richard
MAPIUtilsClass類是否實現IDisposable?如果是這樣,將該吸盤包裝在一個使用中,並應該照顧你的問題。 –