发生COMException:ErrorCode = -2147287036 [英] COMException occurred: ErrorCode = -2147287036

查看:842
本文介绍了发生COMException:ErrorCode = -2147287036的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须并行化一个应用程序;这个应用程序必须处理一个文件,我使用任务,每个线程正在处理一行数据(之前它用于逐行处理行)。问题是数据提供者使用某种缓存并且在此过程中它还多次访问文件 ,因此使用一个数据提供者是一项艰苦的工作线程安全,而不是每次线程处理一行时我在新数据提供程序上创建。它适用于前几次运行,但过了一段时间后,用于访问该文件的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 ErrorCode = -2147287036

我选中2147287036是的错误代码没有足够的资源来打开另一个文件。我确定我正在为数据提供者/ COM对象调用close / dispose,所以我很难理解为什么我无法访问该文件(我有一个异常处理逻辑,试图打开写入模式如果不成功,它会尝试在读取模式中打开它,如果不成功则会再次抛出异常,这基本上就是上面提到的异常。

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).

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

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

推荐答案

我发现了这个问题。有一个内存泄漏,在代码的某些部分,正在创建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.

这篇关于发生COMException:ErrorCode = -2147287036的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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