惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 蓝狐

Java Been, EJB, POJO 之间的区别 Tomcat启动报错Invalid character found in method name. HTTP method names must be tokens Eclipse中Tomcat Server启动后马上又自动停止报错Address已经使用8005端口 Can't assign requested address (Bind failed) Eclipse中Tomcat的配置及简单例子 jsp页面都放在web-inf下面说是要防止用户直接访问jsp页面,为么不能直接访问jsp CATS patch on 20130513 SharePoint 2010 根据不同的用户权限显示不同的导航 (原创)Sharepoint webpart中调用web service报错 vs2010 调试dll文件的方法 sharepoint 2010 打开网站导航管理页面,实现多级菜单 sharepoint 2010中备份和还原的方法 SharePoint2010多级导航配置(转) 说说大型高并发高负载网站的系统架构 (转) 大型网站的架构设计问题----大型高并发高负载网站的系统架构(转) 动态创建类型及属性--转 - 蓝狐 - 博客园 sql 行专列 列转行 普通行列转换 ajaxpro总是运行时语法错误--如何进行JS脚本调试 手动生成WebService代理类的简单办法 (摘) - 蓝狐 - 博客园 由WSDL文件生成WEB service server端C#程序 (摘)
C# SerialPort System.ObjectDisposedException, safe handle...
蓝狐 · 2011-07-22 · via 博客园 - 蓝狐

If I use GC.SuppressFinalize(serialPort.BaseStream), it still doesn't work in my case. Although the serial port object is not disposed by GC, the serial port can't receive data yet.

I find another way, and it works always!

I write a endless loop to check and create a new serial port object if it is disposed by GC.

while (true)

{

Thread.Sleep(60000);

if (serialPort == null)

{

serialPort = new SerialPort(portName, 9600,Parity.None,8);

serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);

serialPort.Open();

}

}

Wish it's usefull for you guys!