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

推荐订阅源

T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
腾讯CDC
小众软件
小众软件
G
Google Developers Blog
V
Visual Studio Blog
罗磊的独立博客
GbyAI
GbyAI
V
V2EX
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
L
LangChain Blog
Engineering at Meta
Engineering at Meta
量子位
The GitHub Blog
The GitHub Blog
博客园 - 司徒正美
WordPress大学
WordPress大学
B
Blog RSS Feed

博客园 - 蓝狐

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!