2011-04-20 69 views
0

我想使用FileStream对象从网络上的不同文件读取数据。 所以我创建了任务(System.Threading.Tasks)来读取所需的部分文件。System.Threading.Tasks和FileStream

相当惊讶的行为。这些任务将引发一个错误:

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. 
} 

人使用任务使用FileStream对象,或有任何想法,为什么我得到这个问题? 谢谢。

+0

你在任务中声明了stm_BaseStream吗? – 2011-04-20 09:00:39

+0

也许你在文件的末尾? – 321X 2011-04-20 09:01:23

+3

错误信息是什么? – 2011-04-20 09:01:56

回答

0

int_ReadBytes的返回值是多少?它可能不等于(int_RecordLength * uint_BufferThis),只是因为文件中没有足够的字节要读取,这会导致您的代码抛出异常。

+0

不是EOF,它仍然有足够的可读性。如果我通过拖动运行指针将代码设置为在调试中重新运行,则它工作正常。 – user696961 2011-04-26 12:50:11