bruhov/WinThumbsPreloader

The app kept crashing on my PC. I changed the following function and it now very stable.

sunny127 opened this issue · 3 comments

Hi, the app kept crashing on my PC. I changed the following function and it now very stable.
using System.IO;
`public void PreloadThumbnail(string filePath)
{
IShellItem shellItem = null;
ISharedBitmap bmp = null;
WTS_CACHEFLAGS cFlags;
WTS_THUMBNAILID bmpId;

        FileAttributes attr = File.GetAttributes(filePath);

        if (!attr.HasFlag(FileAttributes.Directory))
        {
            try
            {
                SHCreateItemFromParsingName(filePath, IntPtr.Zero, iIdIShellItem, out shellItem);

                //TBCache.GetThumbnail(shellItem, 128, WTS_FLAGS.WTS_EXTRACTINPROC, out bmp, out cFlags, out bmpId);
                TBCache.GetThumbnail(shellItem, 128, WTS_FLAGS.WTS_EXTRACT, out bmp, out cFlags, out bmpId);
            }
            catch (Exception)
            {
                //Do nothing
            }
        }
        if (bmp != null) Marshal.ReleaseComObject(bmp);
        if (shellItem != null)  Marshal.ReleaseComObject(shellItem);
        bmp = null;
        shellItem = null;
    }`

can send me a compiled version?

Do this as a Pull Request not an issue.

I experienced application crashes when I used WTS_EXTRACT. I can’t reproduce it now. Maybe the environment is different.

Also, why disable directory thumbnail preloading?