catchexceptionexample.cs
来自「线程池实例,1.1版本,用于代替.net自带线程池」· CS 代码 · 共 48 行
CS
48 行
using System;
using System.Diagnostics;
using Amib.Threading;
namespace Examples
{
public class CatchExceptionExample
{
private class DivArgs
{
public int x;
public int y;
}
public void DoWork()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
IWorkItemResult wir =
smartThreadPool.QueueWorkItem(new
WorkItemCallback(this.DoDiv), divArgs);
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);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?