TextReader Read and ReadToEnd hangs without throwing exception

强颜欢笑 提交于 2019-12-08 02:12:59

问题


Is there a way to know that a call to TextReader.Read or TextReader.ReadToEnd call will hang without throwing exeption before I do the call?


try
{
 using (var filterReader = new EPocalipse.IFilter.FilterReader(tempFileName))
 {
  mediaContent = filterReader.ReadToEnd();
 }
}
catch (Exception e)
{
 Log.Error("DealerPortalIndex Error on file: " + tempFileName, e, this);
 mediaContent = string.Empty;
}

filterReader.ReadToEnd() hangs and never throws exception on a certain .xls file (maybe more file)

I have also tried using a filterReader.Read(char{}, int, int) to read block and get the same problem.


回答1:


(You say textreader in your code, but the example is using EPocalips IFilter module.)

I think it's a bug in EPocalipse IFilter. I don't know how updated their code is, but I recall something to the same effect some years ago when I was working with IFilters and used the EPocalipse code.

You should run it in the debugger and break the code to see where in the EPocalipse library it's hanging. Most likely it's stuck in a loop.

[Edit] I found my old updated code and put it up on skydrive (Epocalipse.IFilter.zip). See if it solves your problems. It has detection for infinite IFilter parse loops, and excel files with locked cells.



来源:https://stackoverflow.com/questions/1883915/textreader-read-and-readtoend-hangs-without-throwing-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!