在类库中捕获过程分离 [英] Capturing Process Detach inside Class Library
问题描述
我已经编写了一个由VC ++ dll包装并由VB 6.0应用程序调用的C#类库.
I have written a C# class library which is wrapped by a VC++ dll and called by a VB 6.0 application.
在VC ++ dll中,我可以捕获进程与DLL分离时的情况(在DllMain内部(内部情况:DLL_PROCESS_DETACH)),然后可以处理所需的进一步处理.
In a VC++ dll i can capture when the process is getting detached from the dll (inside DllMain inside case: DLL_PROCESS_DETACH) and then can handle further processing that is required.
如何在C#类库(DLL)中执行相同的操作?我想知道DLL加载过程何时将自身与DLL分离(或退出).
How can can do the same thing inside a C# Class Library (DLL) ? I want to know when the dll loading process is detaching itself from the DLL (or exiting).
我尝试了Dispose函数,但是没有运气.
I tried with the Dispose function with no luck.
谢谢.
推荐答案
使用 AppDomain.DomainUnload 事件.
You could use AppDomain.DomainUnload event.
using System;
namespace YourClassLibrary
{
public class YourClass
{
public YourClass()
{
AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
}
void CurrentDomain_DomainUnload(object sender, EventArgs e)
{
//Your code goes here.
}
}
}
这篇关于在类库中捕获过程分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!