是Assembly.LoadFrom保持开放的文件句柄?

编程入门 行业动态 更新时间:2024-10-28 11:31:37
本文介绍了是Assembly.LoadFrom保持开放的文件句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用

Assembly.LoadFrom("path.exe");

之后,我似乎无法删除的文件系统EXE。所以我在想,如果这条道路保持一个开放的文件句柄和我怎么能收呢?

and after that i cant seem to delete that exe from the file system. so i was wondering if this path keeps an open file handle and how i can close it?

推荐答案

是的,它是开放的,直到该组件是从应用程序域卸载。

Yes, it is open until the assembly is unloaded from the appdomain.

如果您真的需要删除的文件,其内容加载到内存中。使用 的Assembly.Load(字节[]) 加载程序集:使用

If you really need to delete the file, load its content into memory. The use Assembly.Load(byte[]) to load the assembly:

using (Stream stream = File.OpenRead("path.exe")) { byte[] rawAssembly = new byte[stream.Length]; stream.Read(rawAssembly, 0, (int)stream.Length); Assembly.Load(rawAssembly); }

更多推荐

是Assembly.LoadFrom保持开放的文件句柄?

本文发布于:2023-11-13 11:46:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584279.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:句柄   文件   Assembly   LoadFrom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!