Skip to content

Commit 796e2e3

Browse files
committed
Add ProcessExit handler
1 parent 3cea15f commit 796e2e3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseServer.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,28 @@ public static void Register()
110110
}
111111

112112
AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
113+
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
113114
Logger.Initialization.Info("IntelliSenseServer.Register End");
114115
}
115116

117+
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
118+
{
119+
Logger.Initialization.Verbose("IntelliSenseServer ProcessExit Begin");
120+
if (_isActive)
121+
{
122+
Deactivate();
123+
}
124+
Logger.Initialization.Verbose("IntelliSenseServer PrcessExit End");
125+
126+
}
127+
116128
// DomainUnload runs when AutoClose() would run on the add-in.
117129
// I.e when the add-in is explicitly unloaded via code or the add-ins dialog, or when the add-in is re-loaded
118130
// (reload via File->Open is equivalent to unload, then load).
119131
// We don't expect DomainUnload to run when Excel is shutting down.
120132
static void CurrentDomain_DomainUnload(object sender, EventArgs e)
121133
{
122-
Logger.Initialization.Info("IntelliSenseServer DomainUnload");
134+
Logger.Initialization.Verbose("IntelliSenseServer DomainUnload Begin");
123135
//// Early shutdown notification
124136
//XlCall.ShutdownStarted();
125137

@@ -134,6 +146,7 @@ static void CurrentDomain_DomainUnload(object sender, EventArgs e)
134146
ActivateServer(highestRegistration);
135147
}
136148
}
149+
Logger.Initialization.Verbose("IntelliSenseServer DomainUnload End");
137150
}
138151

139152
// Called internally from the Register() call, or via the control function from another server.
@@ -156,7 +169,7 @@ internal static bool Activate()
156169
}
157170
}
158171

159-
// Called internally from the AppDomain_DomainUnload event handler, and via the control function from another server when that server figures out that it must become the active server.
172+
// Called internally from the AppDomain_DomainUnload or AppDomain_ProcessExit event handler, and via the control function from another server when that server figures out that it must become the active server.
160173
internal static bool Deactivate()
161174
{
162175
try

0 commit comments

Comments
 (0)