mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 13:01:23 +03:00
4d6ffb5851
SmartThreadPool v2.0
35 lines
841 B
C#
35 lines
841 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using Amib.Threading;
|
|
|
|
namespace Examples
|
|
{
|
|
public class CatchExceptionExample
|
|
{
|
|
public void DoWork()
|
|
{
|
|
SmartThreadPool smartThreadPool = new SmartThreadPool();
|
|
|
|
IWorkItemResult<double> wir = smartThreadPool.QueueWorkItem(new Func<double, double, double>(DoDiv), 10.0, 0.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);
|
|
}
|
|
|
|
smartThreadPool.Shutdown();
|
|
}
|
|
|
|
private double DoDiv(double x, double y)
|
|
{
|
|
return x / y;
|
|
}
|
|
}
|
|
}
|