Skip to content

Commit 1e4d91d

Browse files
committed
fix shutdown exception if you closed Notepad++ without ever pulsing
1 parent 5809418 commit 1e4d91d

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

CodeStats/CodeStatsPackage.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,23 @@ internal static void PluginCleanUp()
849849
{
850850
nppStarted = false;
851851

852-
Logger.Debug("Cancelling pulses...");
852+
Logger.Info("Plugin cleanup on shutdown...");
853853

854854
// Flush the current pulse
855+
Logger.Debug("Flushing the current pulse...");
855856
if (pulseQueue != null && currentPulse != null && !currentPulse.isEmpty())
856857
{
857858
pulseQueue.Enqueue(currentPulse);
858859
currentPulse = new Pulse();
859860
currentCount = 0;
860861
}
861862

863+
Logger.Debug("Cancelling pulse processing...");
862864
pulseProcessor_tokensource.Cancel();
863865

864866
if (timer != null)
865867
{
868+
Logger.Debug("Stopping timer...");
866869
timer.Stop();
867870
timer.Elapsed -= ProcessPulses;
868871
timer.Dispose();
@@ -873,8 +876,19 @@ internal static void PluginCleanUp()
873876
}
874877

875878
// test if we can cancel and dump pulses
879+
Logger.Debug("Waiting for pulse processor to be cancelled...");
880+
try
881+
{
882+
if (pulseProcessor != null)
883+
pulseProcessor.Wait();
884+
}
885+
catch (Exception ex)
886+
{
887+
Logger.Error("Exception while waiting for pulse processor to be cancelled", ex);
888+
}
889+
890+
Logger.Debug("Dequeueing remaining queued pulses...");
876891
var jsonSerializer = new JavaScriptSerializer();
877-
pulseProcessor.Wait();
878892
Pulse result;
879893
while (pulseQueue.TryDequeue(out result))
880894
{
@@ -884,6 +898,8 @@ internal static void PluginCleanUp()
884898
Logger.Debug("Unsaved pulse: " + json);
885899
}
886900
}
901+
902+
Logger.Info("Plugin cleanup finished");
887903
}
888904

889905
}

0 commit comments

Comments
 (0)