如果我捕获异常,它也会捕获类型及其基本类型:
try
{
throw new EndpointNotFoundException(...);
}
catch (CommunicationException e)
{
// EndpointNotFoundException is caught (inherits from CommunicationException)
}
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能以同样的方式比较类型呢?
var e = new EndpointNotFoundException(...);
if (e.GetType() == typeof(CommunicationException)) // is not true
{
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以观看Type.BaseType,但是没有最简单的方法来匹配包括其基本类型树在内的类型吗?
我需要在正确的工作线程上调用在计时器线程上运行的方法。Invoke/BeginInvoke 流程对我有用。有2个线程共享一个线程间数据容器进行数据交换。一种是填充队列,一种是处理队列。如果队列在空状态后已满,则会引发事件。所有问题都是由计时器引起的,计时器在其经过的事件上打开新线程。我正在使用调度程序在正确的线程上调度,但除了这个调度程序之外,一切正常。:-)
请问有人看出问题出在哪里了吗?
完整的测试代码在这里: http: //pastebin.com/jqYbR9PS。
调试输出是这样的:
App Thread ID: 9
Processor Thread ID: 10
Processor Dispatcher Thread ID: 10
The thread '<No Name>' (0x888) has exited with code 0 (0x0).
Processor QueueListener caller Thread ID: 12
Processor Dispatcher Thread ID: 10
Processor invoking ProcessQueue.
...here shut be processing output...
Processor invoked ProcessQueue.
App Thread ID on end: 9
The thread 'vshost.RunParkingWindow' (0x17c4) has exited with code 0 (0x0).
The thread '<No Name>' (0x820) has exited with code 0 …Run Code Online (Sandbox Code Playgroud) 有没有办法监控数据库连接中断?我有一个跨应用程序共享的连接,一些对象应该对连接中断做出反应.
理想情况下,它应该是一个事件.我发现的唯一的事情是连接异常,但它是在本地引发的(我正在侦听异常).
我有想法继承DbConnection并监听此对象中的异常(重载其方法),在连接错误异常(通过相关代码)上发出信号.但也许有最简单的方法.
谢谢你的想法.
我是C#的新手,来自PHP.一切都很清楚,除了我不知道究竟是什么意思构造接口/集合<>.
我已经在使用<>作为"类型定义"了,但它究竟意味着什么.我这样使用它:
class TaskComparer : IEqualityComparer<Task> ...
class TaskQueue : ConcurrentQueue<Task> ...
Run Code Online (Sandbox Code Playgroud)
你看到有关于此的任何文章吗?请发布链接.谢谢.