Assembly.LoadFrom 是否保持打开的文件句柄? [英] Is Assembly.LoadFrom keeping an open file handle?

查看:27
本文介绍了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(byte[])a> 加载程序集:

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 是否保持打开的文件句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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