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. 一些不常见的css知识

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

  2. php数组·的方法-数组检索

    /* * //数组检索函数 * */ //array_keys() 获取数组中所有键名 //array_values() 获取数组中所有键名 $arr6=range('a','e'); print_r ...

  3. 转 Celery 使用

    http://www.mamicode.com/info-detail-1798782.html https://blog.csdn.net/lu1005287365/article/details/ ...

  4. 使用vue-cli脚手架安装和webpack-simple模板项目生成

    Vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...

  5. 数据结构---Java---HashMap

    1.概述 [hash冲突]: 对某个元素进行哈希函数运算,得到一个地址值,要进行插入时,发现此地址被占用,称为hash冲突(哈希碰撞): [hash冲突解决]: 开放定址(发生冲突,继续寻找下一块未被 ...

  6. tomcat入门(一)几种常见的使用tomcat部署项目的方式

    1.常规方式部署 直接把web项目复制到tomcat安装目录下的%Tomcat_Home%/webapps/{web项目} 2.使用控制台进行部署 若一个web应用结构为D:\workspace\We ...

  7. PlayMaker 操作界面超级详细介绍

    原文:https://www.indienova.com/u/christiantam/blogread/1214

  8. DedeCMS {dede:field name='array' /}的用法

    field支持用array获取任意字段的值.(支持标记:文章列表模板的 {dede:field name='array' /}.arclist.arclistsg.loop.sql 标签)   例如平 ...

  9. nodejs卸载安装

    作为新手nodejs卸载后安装就总出错,今天记录了详细的步骤: 参考一下网址:写的很详细https://jingyan.baidu.com/article/48b37f8dd141b41a646488 ...

  10. python面试题——前端(23题)

    2.谈谈你对websocket协议的认识. 3.什么是magic string ? 4.如何创建响应式布局? 5.你曾经使用过哪些前端框架? 6.什么是ajax请求?并使用jQuery和XMLHttp ...