.net 2.0下往流输出文本多了抛异常

前天在群里聊天的时候,喵喵提到.net 2.0平台下,有个控制台程序运行时间久了,呃,要说有多久可能一个月那种程度吧,崩了。而且是崩在Console.Write里面。说上网找了以后说是.net平台自己有问题。


这样说的话问题大概出在StreamWriter会用到的某些代码的实现里面?因为Console.Write的行为要说起来,也确实很像StreamWriter,下面的Stream是Standard output(标准输出,C语言里面写stdout)。这种坑感觉就像是编译器的bug一样,比如VC 6.0自带的标准库里给std::string用的std::getline一样,一不小心掉进去的话连错哪里都不知道,因为程序员面对这一类的库,一般第一个只会想到是自己代码哪里不对了吧?

不过后来我又测试了.net 3.0 3.5 4.0 4.5,结论是2.0 3.0 3.5会出现这样的问题,而4.0 4.5不会。和是不是Client Profile没有关系。升级4.0是最直接的办法了。




Calls to cancel() will always fail with boost::asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo function has two issues that should be considered before enabling its use:

  • It will only cancel asynchronous operations that were initiated in the current thread.
  • It can appear to complete without error, but the request to cancel the unfinished operations may be silently ignored by the operating system. Whether it works or not seems to depend on the drivers that are installed.

For portable cancellation, consider using one of the following alternatives:

  • Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
  • Use the close() function to simultaneously cancel the outstanding operations and close the socket.

When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.




电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>