From 98ef675f9c3a04c3287158e73977f34ecba6b964 Mon Sep 17 00:00:00 2001 From: Markus Thurner Date: Mon, 13 Apr 2015 12:27:19 +0200 Subject: [PATCH] Wait for threads to be completed before shutting down, and naming threads for easier debugging. --- TimberWinR/Inputs/WindowsEvtInputListener.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TimberWinR/Inputs/WindowsEvtInputListener.cs b/TimberWinR/Inputs/WindowsEvtInputListener.cs index 478eec7..fcb19d1 100644 --- a/TimberWinR/Inputs/WindowsEvtInputListener.cs +++ b/TimberWinR/Inputs/WindowsEvtInputListener.cs @@ -19,7 +19,7 @@ namespace TimberWinR.Inputs private readonly int _pollingIntervalInSeconds = 1; private readonly WindowsEvent _arguments; private long _receivedMessages; - private List _tasks; + private readonly List _tasks; public bool Stop { get; set; } public WindowsEvtInputListener(WindowsEvent arguments, CancellationToken cancelToken) @@ -31,7 +31,7 @@ namespace TimberWinR.Inputs foreach (string eventHive in _arguments.Source.Split(',')) { - var thread = new Thread(EventWatcher); + var thread = new Thread(EventWatcher) {Name = "Win32-Eventlog-" + eventHive}; _tasks.Add(thread); thread.Start(eventHive); } @@ -40,7 +40,11 @@ namespace TimberWinR.Inputs public override void Shutdown() { Stop = true; - LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType); + LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType); + foreach (var thread in _tasks) + { + thread.Join(); + } base.Shutdown(); }