Fixed wrongly casting Exceptions to WorkItem's TResult

Also added UnitTest

Thanks to Zdenek who pointed this.
This commit is contained in:
Ami Bar
2014-04-15 00:26:05 +03:00
parent 4eb7cf7302
commit 0286161d40
2 changed files with 25 additions and 7 deletions
+24 -6
View File
@@ -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();
}
}
}
+1 -1
View File
@@ -103,7 +103,7 @@ namespace Amib.Threading.Internal
public object Exception
{
get { return (TResult)_workItemResult.Exception; }
get { return _workItemResult.Exception; }
}
#region IInternalWorkItemResult Members