从Outlook pst文件释放内存时出现问题 [英] Problem in releasing memory from an Outlook pst file

查看:221
本文介绍了从Outlook pst文件释放内存时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个访问Outlook个人文件夹的win应用程序。在内部,它在Outlook实例上安装个人文件夹,并处理邮件,然后卸载pst。卸载pst后,我删除该文件。

I am working on a win app which accesses the Outlook personal folders. Internally, it mounts the personal folder on the Outlook instance and processes the mails and then unmounts the pst. After unmounting the pst, I delete that file.

现在的问题是,即使卸载pst和释放内存后,当我尝试删除pst,我得到某个进程正在使用此文件,因此无法将其删除的例外。这个过程是展望。我使用下面的代码来卸载和释放内存:

Now the problem is that even after un mounting the pst and releasing memory, when I try to delete the pst, I get an exception that some process is using this file so it can not be deleted. And that process is outlook. I am using following code to un mount and release memory:

 _application.Session.RemoveStore(_personalFolder);
 while (System.Runtime.InteropServices.Marshal.ReleaseComObject(_personalFolder) >= 0) ;
 _personalFolder = null;

我检查过很多次,似乎需要一些时间来释放内存,明确时间为此。

I checked it many times and it seems as if it takes some time to release memory and there is no definite time for this. Could any one help me how to delete the file?

推荐答案

请查看 KB234228(OL97:Outlook .pst文件锁释放间隔现在可配置)。这是关于Outlook 97,但我会猜想它仍然可以工作。

Have a look at KB234228 ("OL97: Outlook .pst File Lock Release Interval Now Configurable"). It is about Outlook 97, but I would guess that it still works.

我猜想 FileSystemWatcher 不会帮助你,因为没有独占锁释放事件。

I guess that FileSystemWatcher will not help you, since there is no "exclusive lock released" event.

所以也许你可以创建一个工作线程,不断尝试删除所有的.pst文件放入队列。这样,您的应用程序UI至少可以不间断地运行。

So maybe you can make a worker thread, that continuously tries to delete all the .pst files you put in a queue. This way your application UI can at least go on uninterrupted.

ProcMon 有能力查看应用程序的文件句柄。也许你能够做一个API调用,允许你这样做的Oulook过程(这是另一个SO问题的好材料,我猜)。这样,您不必轮询文件系统,并且可以更快地在锁失效后。

Tools like ProcMon do have the ability to look at the file handles of applications. Maybe you are able to make an API call that allows you doing that for the Oulook process (That's good material for another SO question, I guess). This way you don't have to poll the file system, and can act more quickly when the lock is gone.

如果你敢,你甚至可以尝试立即关闭问题的文件句柄,而不需要轮询/等待。

If you dare, you might even try and close the file handle in question right away, removing the need to poll/wait altogether.

这篇关于从Outlook pst文件释放内存时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆