I have written a Windows Service that utilizes the file system watcher on a folder that gets a ton of images uploaded to it. When it gets notified of a file being put in the directory (or any subdirectory), it spawns a task to check the file to see its current quality setting, creates a new, temporary file based on the original file, sets that file's quality to 70, saves the temp file and finally, writes the temp file over the original file.
I'm having a couple problems with this. First, it looks like IM is crashing in my call to get the information about the original file randomly sometimes (don't have a reproducible case yet, but I'm trying to isolate - it seems to happen fairly frequently) and I can't catch the exception:
Code: Select all
Application: PixMonService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.SEHException
at ImageMagick.MagickImage+NativeMethods+X86.MagickImage_ReadFile(IntPtr, IntPtr ByRef)
at ImageMagick.MagickImage+NativeMagickImage.ReadFile(ImageMagick.MagickSettings)
at ImageMagick.MagickImage.Read(System.String, ImageMagick.MagickReadSettings, Boolean)
at ImageMagick.MagickImage..ctor(System.String)
at PixMonService.PixMonService.ShrinkPicture(System.String)
at PixMonService.PixMonService+_Closure$__25-0._Lambda$__0()
at System.Threading.Tasks.Task`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.Tasks.Task.ExecutionContextCallback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Thread...
Faulting module name: Magick.NET-Q8-x86.Native.dll, version: 7.0.6.100, time stamp: 0x59465775
Exception code: 0xc0000006
Fault offset: 0x001943f0
Faulting process id: 0x16f4
Faulting application start time: 0x01d2f8315afe6f2c
Faulting application path: C:\Program Files (x86)\path\PixMonService\PixMonService.exe
Faulting module path: C:\Users\administrator\AppData\Local\Temp\Magick.NET.net40.7.0.6.100\Magick.NET-Q8-x86.Native.dll
Report Id: 56ccfc1e-65c1-11e7-80cf-b083fec668dd
In case you were wondering why I didn't use a script (I previously was), it is because I'm monitoring from another server than where the files are and the FileSystemWatcher can throw a lot of events quickly and I didn't want to miss them, so it starts a task to do the work so it can get back to monitoring for changes. I am also using a slightly modified FileSystemWatcher that automatically will reconnect in the event of a loss of connectivity to the source to monitor (https://petermeinl.wordpress.com/2015/0 ... emwatcher/).
I have posted one each of files that are missing data, successfully compressed, and uncompressed, all from the same folder, as well as the code I'm using in my Dropbox. https://www.dropbox.com/sh/4qos9451juhn ... oXgSa?dl=0
If anyone can see what it is that I'm missing and help me out, that would be greatly appreciated. Right now I've got it disabled since yesterday, it corrupted a bunch of files and now I have to go find them and hope there is a backup of them.
Environment:
Image server and compressing server both Windows Server 2012 R2, up to date with patching
ImageMagick 7.0.6(.100) Q8 32-bit
VisualStudio 2017
The "Tamed FileSystemWatcher" from 7/1/15