在类库中捕获过程分离 [英] Capturing Process Detach inside Class Library

查看:78
本文介绍了在类库中捕获过程分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个由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屋!

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