mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 09:01:19 +03:00
Fixed wrongly casting Exceptions to WorkItem's TResult
Also added UnitTest Thanks to Zdenek who pointed this.
This commit is contained in:
@@ -75,13 +75,31 @@ namespace SmartThreadPoolTests
|
||||
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsTrue(e is DivideByZeroException);
|
||||
}
|
||||
|
||||
private object DoDiv(object state)
|
||||
{
|
||||
DivArgs divArgs = (DivArgs)state;
|
||||
return (divArgs.x / divArgs.y);
|
||||
}
|
||||
|
||||
private object DoDiv(object state)
|
||||
{
|
||||
DivArgs divArgs = (DivArgs)state;
|
||||
return (divArgs.x / divArgs.y);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionType()
|
||||
{
|
||||
SmartThreadPool smartThreadPool = new SmartThreadPool();
|
||||
|
||||
var workItemResult = smartThreadPool.QueueWorkItem(new Func<int>(ExceptionMethod));
|
||||
|
||||
smartThreadPool.WaitForIdle();
|
||||
|
||||
Assert.IsInstanceOf<NotImplementedException>(workItemResult.Exception);
|
||||
|
||||
smartThreadPool.Shutdown();
|
||||
}
|
||||
|
||||
public int ExceptionMethod()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Amib.Threading.Internal
|
||||
|
||||
public object Exception
|
||||
{
|
||||
get { return (TResult)_workItemResult.Exception; }
|
||||
get { return _workItemResult.Exception; }
|
||||
}
|
||||
|
||||
#region IInternalWorkItemResult Members
|
||||
|
||||
Reference in New Issue
Block a user