From 3c10f055892eb83f1df9d1311ae6dfacaa9eb5c6 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Fri, 18 Sep 2009 21:14:27 +0000 Subject: [PATCH] Re-added the default exception handler which will now re-throw the exception, thereby mimicking the behavior of .NET's ThreadPool; wrote unit test to verify the default exception handler is working git-svn-id: file:///srv/devel/repo-conversion/nusu@179 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/AffineThreadPool.Test.cs | 13 +++++++++++++ Source/AffineThreadPool.cs | 14 +++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Source/AffineThreadPool.Test.cs b/Source/AffineThreadPool.Test.cs index 3080862..5c906f1 100644 --- a/Source/AffineThreadPool.Test.cs +++ b/Source/AffineThreadPool.Test.cs @@ -249,6 +249,19 @@ namespace Nuclex.Support { } + /// + /// Tests whether the afine thread pool's default exception handler works + /// as expected + /// + [Test] + public void TestDefaultExceptionHandler() { + Assert.Throws( + delegate() { + AffineThreadPool.ExceptionHandler(new ArrayTypeMismatchException("Test")); + } + ); + } + /// /// Verifies that the waiting work items count and active thread count are /// updated by the thread pool. diff --git a/Source/AffineThreadPool.cs b/Source/AffineThreadPool.cs index f828f3f..31d4234 100644 --- a/Source/AffineThreadPool.cs +++ b/Source/AffineThreadPool.cs @@ -165,6 +165,14 @@ namespace Nuclex.Support { } } + /// + /// Default handler used to respond to unhandled exceptions in ThreadPool threads + /// + /// Exception that has occurred + internal static void DefaultExceptionHandler(Exception exception) { + throw exception; + } + /// A thread worker function that processes items from the work queue private static void ProcessQueuedItems() { @@ -198,7 +206,7 @@ namespace Nuclex.Support { thread.IdealProcessor = hardwareThreadIndex; } #endif - + // Keep processing tasks indefinitely for(; ; ) { UserWorkItem workItem = getNextWorkItem(); @@ -231,7 +239,7 @@ namespace Nuclex.Support { return threads[index]; } } - + return null; } #endif @@ -264,7 +272,7 @@ namespace Nuclex.Support { } /// Delegate used to handle assertion checks in the code - public static volatile ExceptionDelegate ExceptionHandler; + public static volatile ExceptionDelegate ExceptionHandler = DefaultExceptionHandler; #if !XBOX360 /// Retrieves the calling thread's thread id