问题
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