发生 COMException:错误代码 = -2147287036

发布于 2024-10-21 04:40:28 字数 551 浏览 3 评论 0原文

我必须并行化一个应用程序;这个应用程序必须处理一个文件,我使用了任务,每个线程正在处理一行数据(以前它用于顺序地逐行处理)。问题在于数据提供程序使用某种缓存,并且在此过程中多次访问文件,因此使用一个数据提供程序是一项艰巨的工作线程安全,相反,每次线程处理一行时,我都会在新的数据提供程序上创建。它在前几次运行中工作正常,但一段时间后,用于访问文件的 COM 对象开始抛出以下错误:

发生 COMExceptionErrorCode = -2147287036

正如我所检查的,“2147287036”是“没有足够的资源来打开另一个文件”的错误代码。我确定我正在调用数据提供程序/COM 对象的关闭/处置,因此我很难理解为什么我无法访问该文件(我有一个异常处理逻辑,尝试在 < strong>写模式,如果不成功,它会尝试以读模式打开它,如果不成功,它会再次抛出异常,基本上就是上面提到的异常)。

我的第一个线索是 COM 对象不会立即释放文件句柄。但这仍然没有多大意义。

I have to parallelize an application; This application has to process a file, I used tasks and each thread is processing one line of data (previously it used to process lines one by one sequentially). The problem is that the data provider uses some sort of caching and also it accesses the file multiple times during the process, so using one data provider was a hard work of making it thread-safe, instead I created on new data provider for each time a thread is processing a line. It works fine for the first couple of runs, but after some time the COM object which is used to access the file starts throwing the following error:

COMException occurred: ErrorCode = -2147287036

As I checked "2147287036" is the error code for "not enough resources to open another file". I'm sure I'm calling the close/dispose for the data providers/COM objects, so I have a hard time understanding why I can not access the file (I have an exception handling logic that tries to open the file in the write mode and if it is unsuccessful, it tries to open it in the read mode, and again if it is unsuccessful it throws the exception which is basically the one mentioned above).

My first clue is that the COM object doesn't release the file handle instantly. But still that doesn't make that much sense.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九厘米的零° 2024-10-28 04:40:28

如果有一个生产者/消费者设置,其中单个生产者逐行读取文件并将其输入到消费者线程可以全力以赴的队列中,不是更好吗?

从多个线程打开同一个文件来进行繁重的处理听起来有点麻烦。

抱歉,如果我没理解你的问题。

Wouldn't it be better to have a producer/consumer setup where a single producer reads in the file line by line and feeds that into a queue where the consumer threads can go all out?

Opening the same file from multiple threads to do heavy crunching just sounds a bit cumbersome.

Sorry if I miss-understood your issue.

夜访吸血鬼 2024-10-28 04:40:28

我发现了这个问题。存在内存泄漏,在代码的某些部分中,正在创建 COM 对象的某些副本但未释放,显然 Marshal.ReleaseComObject(...) 会递减与 COM 对象的引用数量相对应的计数器,并且仅释放如果该数字变为 0。

I found the issue. There was a memory leak, in some parts of the code some copies of the COM object was being created and not released and apparently Marshal.ReleaseComObject(...) decrements the counter corresponding to the number of references to the COM object and only releases it if that number becomes 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文