Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the DotNet Core alternative to AppDomain.CurrentDomain.ProcessExit event?

Tags:

.net

.net-core

I want to do some cleanup in a library when the process is being closed, what is the DotNet Core alternative for that? In .Net Framework 4 I used AppDomain.CurrentDomain.ProcessExit.

like image 599
somdoron Avatar asked Jul 03 '16 15:07

somdoron


1 Answers

Since your code is in a library you can make the caller of the library provide a notification. That way the host can decide to notify you.

Normally, a library is not supposed to mess with process global state. It should not assume much about the environment it's being hosted it.

Maybe the caller can pass a Task that becomes completed when process shutdown starts. Or, the caller can call a static method on your library (NotifyProcessShutdown or PerformProcessShutdownCleanup).

like image 116
usr Avatar answered Nov 25 '22 22:11

usr