在控制台应用程序中不会引发AppDomain.CurrentDomain.DomainUnload [英] AppDomain.CurrentDomain.DomainUnload not be raised in Console app

查看:45
本文介绍了在控制台应用程序中不会引发AppDomain.CurrentDomain.DomainUnload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序集,当访问该程序集时,它会旋转一个线程来处理放置在队列中的项目.在该程序集中,我将一个处理程序附加到DomainUnload事件:

AppDomain.CurrentDomain.DomainUnload + =新的EventHandler(CurrentDomain_DomainUnload);

该处理程序将线程连接到主线程,以便队列中的所有项目都可以在应用程序终止之前完成处理.

我遇到的问题是,当控制台应用程序终止时,不会触发DomainUnload事件.任何想法为什么会这样?

使用.NET 3.5和C#

解决方案

对于您来说,不幸的是,此事件不会在默认的AppDomain中引发,而只会在默认域中创建的应用程序域中引发.

来自 MSDN文档:

此事件从未在默认的应用程序域.

I have an assembly that when accessed spins up a single thread to process items placed on a queue. In that assembly I attach a handler to the DomainUnload event:

AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);

That handler joins the thread to the main thread so that all items on the queue can complete processing before the application terminates.

The problem that I am experiencing is that the DomainUnload event is not getting fired when the console application terminates. Any ideas why this would be?

Using .NET 3.5 and C#

解决方案

Unfortunately for you, this event is not raised in the default AppDomain, only in app domains created within the default one.

From the MSDN documentation:

This event is never raised in the default application domain.

这篇关于在控制台应用程序中不会引发AppDomain.CurrentDomain.DomainUnload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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