开发者

System.Threading.Tasks and FileStream

I am trying to read开发者_如何学运维 data from different files on network using FileStream object. So I created Tasks (System.Threading.Tasks) to read parts of the files required.

Quite surprised by the behaviour. These Tasks throws an error :

int_ReadBytes = stm_BaseStream.Read (byt_buffer, 0, ( int ) ( int_RecordLength * uint_BufferThis ));

if (int_ReadBytes != ( int_RecordLength * uint_BufferThis ))
{
       throw new Exception ("Could not read record");
       // throws an error here. 
} 

Anyone used Task with FileStream objects, or has any idea why I am getting this issue? Thanks.


what is the returned value of int_ReadBytes? It may not be equal to (int_RecordLength * uint_BufferThis) simply because there are not enough bytes in the file to read, which will casue your code to throw an exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜