小编Fan*_*nda的帖子

比较类型,包括 C# 中的基本类型

如果我捕获异常,它也会捕获类型及其基本类型:

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,但是没有最简单的方法来匹配包括其基本类型树在内的类型吗?

c# comparison types

4
推荐指数
1
解决办法
364
查看次数

C# 控制台应用程序中的调度程序问题

我需要在正确的工作线程上调用在计时器线程上运行的方法。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)

c# multithreading dispatcher

2
推荐指数
1
解决办法
6541
查看次数

.NET如何监控数据库连接中断?

有没有办法监控数据库连接中断?我有一个跨应用程序共享的连接,一些对象应该对连接中断做出反应.

理想情况下,它应该是一个事件.我发现的唯一的事情是连接异常,但它是在本地引发的(我正在侦听异常).

我有想法继承DbConnection并监听此对象中的异常(重载其方法),在连接错误异常(通过相关代码)上发出信号.但也许有最简单的方法.

谢谢你的想法.

.net c# database

1
推荐指数
1
解决办法
531
查看次数

在C#中究竟意味着什么?

我是C#的新手,来自PHP.一切都很清楚,除了我不知道究竟是什么意思构造接口/集合<>.

我已经在使用<>作为"类型定义"了,但它究竟意味着什么.我这样使用它:

class TaskComparer : IEqualityComparer<Task> ...
class TaskQueue : ConcurrentQueue<Task> ...
Run Code Online (Sandbox Code Playgroud)

你看到有关于此的任何文章吗?请发布链接.谢谢.

.net c# generics

0
推荐指数
1
解决办法
135
查看次数

标签 统计

c# ×4

.net ×2

comparison ×1

database ×1

dispatcher ×1

generics ×1

multithreading ×1

types ×1