mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 13:01:23 +03:00
v2.0
SmartThreadPool v2.0
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user