Recover From Access Violation Exception

笑着哭i 提交于 2019-12-13 06:17:57

问题


I am using EZTwain (an unmanaged dll) to process some PDF's. I am aware it can only read PDF's that it has created. Unfortunately in the real world it is encountering PDFs which have been created by other libraries. This causes it to fail and throw an AccessViolationException.

This in itself is not a huge problem as my C# app continues on its way. Unfortunately when it next comes to this file and tries to reprocess it, it is still locked. Presumably EZTwain is still loaded...in what state i don't know - but has been left with the file lock.

Is there anyway i can force the DLL to unload and so release the lock on the file (P/Invoke calls or otherwise)?

If i can achieve this i can then skip use of EZTwain the second time around.

Cheers

[UPDATE]

I have tried calling LoadLibrary, catching the access violation exception and then FreeLibrary but my file is still locked.

I've checked with Process Explorer: the DLL is definitely being unloaded but the file remains locked...how come?

(Looks like i will have to go with the app domain or separate Exe suggestion)

来源:https://stackoverflow.com/questions/16042092/recover-from-access-violation-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!