SmartThreadPool v2.0
This commit is contained in:
Ami Bar
2009-12-19 16:32:41 +02:00
parent b30b4abdda
commit 4d6ffb5851
89 changed files with 13714 additions and 2639 deletions
+21 -34
View File
@@ -6,42 +6,29 @@ namespace Examples
{
public class CatchExceptionExample
{
private class DivArgs
{
public int x;
public int y;
}
public void DoWork()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
public void DoWork()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemResult<double> wir = smartThreadPool.QueueWorkItem(new Func<double, double, double>(DoDiv), 10.0, 0.0);
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
try
{
double result = wir.Result;
}
// Catch the exception that Result threw
catch (WorkItemResultException e)
{
// Dump the inner exception which DoDiv threw
Debug.WriteLine(e.InnerException);
}
IWorkItemResult wir =
smartThreadPool.QueueWorkItem(new
WorkItemCallback(this.DoDiv), divArgs);
smartThreadPool.Shutdown();
}
try
{
int result = (int)wir.Result;
}
// Catch the exception that Result threw
catch (WorkItemResultException e)
{
// Dump the inner exception which DoDiv threw
Debug.WriteLine(e.InnerException);
}
smartThreadPool.Shutdown();
}
private object DoDiv(object state)
{
DivArgs divArgs = (DivArgs)state;
return (divArgs.x / divArgs.y);
}
}
private double DoDiv(double x, double y)
{
return x / y;
}
}
}