Thread.Abort对UdpClient.Receive阻塞的线程无效

http://computer-programming-forum.com/4-csharp/184f9d4ee63704fc.htm

This is not a bug (just very poorly documented :)

Thread.Abort throws an exception only when the thread is in managed code. 
Since calling UdpClient.Receive call a blocking function of the WinSock API 
it will not receive the abort exception. Only after UdpClient.Receive 
finishes (hence you are back in managed code) the Thread.Abort method 
re-throws the exception. Lookup in the help files at Thread.Abort().

How to solve this problem? 
Use a Socket class (instead of UdpClient) and use the asynchronously methods 
BeginReceiveFrom and EndReceiveFrom (of course also for XXXSendTo). These 
methods are a litter harder to use but your thread now remains in managed 
code while waiting for the receive operation (still unmanaged code) to 
complete.

-- 
Sander Leer

Quote:
> If a thread is waiting on a call to UdpClient.Receive, there is no way to 
> return from this call unless the UdpClient is closed or data is received. 
> Calling Thread.Abort on the blocked thread has no effect.

> The attached code illustrates the problem.

> Is this a bug?

> DAve

封装Socket.BeginReceive/EndReceive以支持Timeout

http://www.cnblogs.com/dytes/archive/2012/08/13/SocketAsyncOpWithTimeout.html

用到UdpClient的一点经验的更多相关文章

  1. 使用VS2010开发Qt程序的一点经验

    导读 相比于Qt Creator,我更喜欢用VS2010来进行开发.虽然启动时间相对较慢,但是VS下强大的快捷键和丰富的插件,以及使用多年的经验,都让我觉得在开发过程中得心应手.其中最重要的一点是,有 ...

  2. 使用VS2010开发Qt程序的一点经验(转载)

    转载:http://www.cnblogs.com/csuftzzk/p/VS_Qt_Experience.html 导读 相比于Qt Creator,我更喜欢用VS2010来进行开发.虽然启动时间相 ...

  3. 关于删除 hao123 主页设置的一点经验

    :first-child { margin-top: 0px; } blockquote>:last-child { margin-bottom: 0px; } --> 说一说关于删除 h ...

  4. 计算机顶级会议Rankings && 英文投稿的一点经验

    英文投稿的一点经验[转载] From: http://chl033.woku.com/article/2893317.html 1. 首先一定要注意杂志的发表范围, 超出范围的千万别投,要不就是浪费时 ...

  5. Python爬虫脚本 ,Uni-APP复选框做出双向绑定 ,Net5工作流建模 。的一点经验

    从业C#开发多年,现在也经常用到Python 做网络爬虫 ,用Uni-app做手机前端.攒了一点经验.供其他多语言开发程序员借鉴吧. Python做爬虫和其他的方式做爬虫最大的区别应该在于. Pyth ...

  6. 封装RabbitMQ.NET Library 的一点经验总结

    这篇文章内容会很短,主要是想给大家分享下我最近在做一个简单的rabbitmq客户端类库的封装的经验总结,说是简单其实一点都不简单.为了节省时间我主要按照Library的执行顺序来介绍,在你看来这里仅仅 ...

  7. 关于访问MSMQ远端私有队列的一点经验

    这里应该将私有队列称做"专用队列"好像更贴切一些了,O(∩_∩)O 可以访问远程主机的MSMQ的私有队列的,这个是毋庸置疑的,但需要说明的是不能通过代码创建私有队列,关于这一点,我 ...

  8. 封装RabbitMQ.NET Library 的一点经验总结 转载

    这篇文章内容会很短,主要是想给大家分享下我最近在做一个简单的rabbitmq客户端类库的封装的经验总结,说是简单其实一点都不简单.为了节省时间我主要按照Library的执行顺序来介绍,在你看来这里仅仅 ...

  9. 关于Listview布局的一点经验

    1.尽量是给item一个固定高度,最外层不要设高度,里面套一层设置一个固定高度:如果用wrap_content的话,之后用alignTop等会出奇怪的问题. 2.如果要使用alignTop align ...

随机推荐

  1. NET CORE Learning

    ASP.NET Core 基础教程https://www.cnblogs.com/lonelyxmas/tag/ASP.NET%20Core%20%E5%9F%BA%E7%A1%80%E6%95%99 ...

  2. 一些不常见的css知识

    margin-top:20%  ----------------20% 是宽度的20%

  3. File "<ipython-input-20-ac8d4b51998e>"

    环境:Python 3.6 word = "Jesse" ") File "<ipython-input-20-ac8d4b51998e>" ...

  4. shell 0学习

    例一:列出/home 文件夹下的所有文件和目录的详细资料,可以使用如下命令:  ls -a -l /home   ls -al /home 例二:列出当前目录中所有以”d”开头的文件目录的详细内容,可 ...

  5. js中的内置对象

    在js里,一切皆为或者皆可以被用作对象.可通过new一个对象或者直接以字面量形式创建变量(如var i="aaa"),所有变量都有对象的性质.注意:通过字面量创建的对象在调用属性和 ...

  6. 夜神模拟器连不上adb的解决办法

    解决办法: 1.任务管理器里看下,adb.exe以及nox_adb.exe这2个进程有没有在运行?有的话就结束掉 2.找到开发环境的SDK的目录和夜神模拟器的目录,将SDK\platform-tool ...

  7. Murano Weekly Meeting 2015.10.06

    Meeting time:  2015.October.6th 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summar ...

  8. OpenStack Weekly Rank 2015.08.10

    Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 5 1 1 6 12 Sw ...

  9. Linux Bird

    o / : 2GB o /boot: 200MB o /usr : 4GB o /var : 2GB o /tmp : 1GB o swap : 1GB o /home: 5GB,并且使用 LVM 模 ...

  10. 表单(form)成为 ajax 提交的表单(form)

    1.form <form id="ff" method="post"> <div> <label for="name&q ...