Re-worked Windows Event shutdown to use Thread.Abort to enable shuting down in a quicker fashion.

This commit is contained in:
Eric Fontana
2014-11-21 09:06:13 -05:00
parent fc1d7402d0
commit 05142d2a8f
12 changed files with 58 additions and 13 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.11.0")]
[assembly: AssemblyFileVersion("1.3.11.0")]
[assembly: AssemblyVersion("1.3.12.0")]
[assembly: AssemblyFileVersion("1.3.12.0")]

View File

@@ -41,6 +41,7 @@ namespace TimberWinR.Inputs
public override void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
base.Shutdown();
}

View File

@@ -59,9 +59,12 @@ namespace TimberWinR.Inputs
public void Finished()
{
FinishedEvent.Set();
LogManager.GetCurrentClassLogger().Info("Finished Shutdown {0}", InputType);
}
public virtual void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
FinishedEvent.WaitOne();
try
{

View File

@@ -53,6 +53,7 @@ namespace TimberWinR.Inputs
public override void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
base.Shutdown();
}

View File

@@ -28,7 +28,8 @@ namespace TimberWinR.Inputs
}
public override void Shutdown()
{
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
base.Shutdown();
}

View File

@@ -52,6 +52,8 @@ namespace TimberWinR.Inputs
public override void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
this._tcpListenerV4.Stop();
this._tcpListenerV6.Stop();

View File

@@ -60,7 +60,9 @@ namespace TimberWinR.Inputs
public override void Shutdown()
{
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
_udpListener.Close();
Finished();
base.Shutdown();
}
@@ -84,7 +86,8 @@ namespace TimberWinR.Inputs
}
catch (Exception ex)
{
LogManager.GetCurrentClassLogger().Error(ex);
if (!CancelToken.IsCancellationRequested)
LogManager.GetCurrentClassLogger().Error(ex);
}
Finished();

View File

@@ -41,6 +41,7 @@ namespace TimberWinR.Inputs
public override void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
base.Shutdown();
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
@@ -25,22 +26,31 @@ namespace TimberWinR.Inputs
private int _pollingIntervalInSeconds = 1;
private TimberWinR.Parser.WindowsEvent _arguments;
private long _receivedMessages;
private List<Thread> _tasks { get; set; }
public WindowsEvtInputListener(TimberWinR.Parser.WindowsEvent arguments, CancellationToken cancelToken)
: base(cancelToken, "Win32-Eventlog")
{
_arguments = arguments;
_pollingIntervalInSeconds = arguments.Interval;
_tasks = new List<Thread>();
foreach (string eventHive in _arguments.Source.Split(','))
{
string hive = eventHive.Trim();
Task.Factory.StartNew(() => EventWatcher(eventHive));
var thread = new Thread(new ParameterizedThreadStart(EventWatcher));
_tasks.Add(thread);
thread.Start(eventHive);
}
}
public override void Shutdown()
{
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
foreach(Thread t in _tasks)
{
t.Abort();
}
base.Shutdown();
}
@@ -64,8 +74,10 @@ namespace TimberWinR.Inputs
return json;
}
private void EventWatcher(string location)
private void EventWatcher(object ploc)
{
string location = ploc.ToString();
LogQuery oLogQuery = new LogQuery();
LogManager.GetCurrentClassLogger().Info("WindowsEvent Input Listener Ready");
@@ -147,13 +159,32 @@ namespace TimberWinR.Inputs
rs = null;
}
}
catch (System.Threading.ThreadAbortException tex)
{
Thread.ResetAbort();
break;
}
catch (Exception ex)
{
LogManager.GetCurrentClassLogger().Error(ex);
LogManager.GetCurrentClassLogger().Error(ex);
}
Thread.CurrentThread.Priority = ThreadPriority.Normal;
System.Threading.Thread.Sleep(_pollingIntervalInSeconds * 1000);
try
{
Thread.CurrentThread.Priority = ThreadPriority.Normal;
System.Threading.Thread.Sleep(_pollingIntervalInSeconds * 1000);
}
catch (System.Threading.ThreadAbortException tex)
{
Thread.ResetAbort();
break;
}
catch (Exception ex)
{
LogManager.GetCurrentClassLogger().Error(ex);
}
}
Finished();

View File

@@ -48,6 +48,8 @@ namespace TimberWinR
foreach (InputListener listener in Listeners)
listener.Shutdown();
LogManager.GetCurrentClassLogger().Info("Completed ShutDown");
}

View File

@@ -1,7 +1,7 @@
$packageName = 'TimberWinR-${version}' # arbitrary name for the package, used in messages
$installerType = 'msi' #only one of these: exe, msi, msu
$url = 'http://www.ericfontana.com/TimberWinR/TimberWinR-${version}.0.msi' # download url
$silentArgs = '{0084CE8C-1F06-4B74-9EB4-C3067850B173} /quiet'
$silentArgs = '{ABD20B9E-8628-40AD-AB11-5BD4356F9D94} /quiet'
$validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx
UnInstall-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" -validExitCodes $validExitCodes

View File

@@ -13,9 +13,9 @@
<projectUrl>https://github.com/efontana/TimberWinR</projectUrl>
<tags>TimberWinR admin</tags>
<copyright></copyright>
<iconUrl>http://www.ericfontana.com/timberwinr.jpg</iconUrl>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!--<iconUrl>http://cdn.rawgit.com/__CHOCO_PKG_MAINTAINER_REPO__/master/icons/TimberWinR.png</iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<dependencies>
<dependency id="LogParser" version="2.2.0.1" />
</dependencies>