I currently have a requirement to be able to kill an attempt to open an Excel file (this is also needed for Word and PowerPoint, but will look at Excel first), and when it is taking longer than a preset time limit stop/kill it. Currently I have the attempt to open the Excel file in an individual thread. When I call ExcelOpenThread.Abort(), the thread ends and as part of that calls the ExcelEngine instance dispose method. The issue is when I'm processing a batch of files with multiple files taking longer than the time out limit, the application becomes extremely unstable when I start closing threads. The error that it comes up with is "A heap has been corrupted" error. I've done some investigation in my code and the issue seems to come from the XlsIO library.
The code is the thread is only trying to open the file and set a status on whether it can or can't. If it can't then also capture the reason why.
I've had a look at XlsIO and I can't see a method to say "Stop trying to open that file" or "time out opening after...."
Does anyone have any advice. This ability to stop an attempt to open an Excel file if it is taking longer than the allowed time is a must have for application I'm working on.
I've managed to capture two errors, which are below.
Unhandled exception at 0x000000007791F262 (ntdll.dll) in TestOfficeFilesWithSyncfusion.exe: 0xC0000374: A heap has been corrupted (parameters: 0x0000000077998430).
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Syncfusion.XlsIO.Implementation.Heap.HeapFree(IntPtr hHeap, Int32 dwFlags, IntPtr lpMem)
at Syncfusion.XlsIO.Implementation.Collections.RowStorage.Dispose(Boolean disposing)
at Syncfusion.XlsIO.Implementation.WorkbookImpl.Close(Boolean SaveChanges, String Filename)