}
private static readonly Dictionary<string, SwitchValueState> s_switchMap = new Dictionary<string, SwitchValueState>();
+ static AppContext()
+ {
+ // Unloading event must happen before ProcessExit event
+ AppDomain.CurrentDomain.ProcessExit += OnUnloading;
+ AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
+
+ // populate the AppContext with the default set of values
+ AppContextDefaultValues.PopulateDefaultValues();
+ }
+
public static string BaseDirectory
{
get
}
}
- public static event System.EventHandler ProcessExit
- {
- add
- {
- AppDomain.CurrentDomain.ProcessExit += value;
- }
- remove
- {
- AppDomain.CurrentDomain.ProcessExit -= value;
- }
+ public static event System.EventHandler ProcessExit;
+ public static event System.EventHandler Unloading;
+
+ private static void OnProcessExit(object sender, EventArgs e)
+ {
+ var processExit = ProcessExit;
+ if (processExit != null)
+ {
+ processExit(null, EventArgs.Empty);
+ }
}
- #region Switch APIs
- static AppContext()
+ private static void OnUnloading(object sender, EventArgs e)
{
- // populate the AppContext with the default set of values
- AppContextDefaultValues.PopulateDefaultValues();
+ var unloading = Unloading;
+ if (unloading != null)
+ {
+ unloading(null, EventArgs.Empty);
+ }
}
+ #region Switch APIs
/// <summary>
/// Try to get the value of the switch.
/// </summary>
// Since unloading an AssemblyLoadContext is not yet implemented, this is a temporary solution to raise the
// Unloading event on process exit. Register for the current AppDomain's ProcessExit event, and the handler will in
// turn raise the Unloading event.
- AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
+ AppContext.Unloading += OnAppContextUnloading;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
#endif // FEATURE_MULTICOREJI
}
- private void OnProcessExit(object sender, EventArgs e)
+ private void OnAppContextUnloading(object sender, EventArgs e)
{
var unloading = Unloading;
if (unloading != null)