Several problems in VB service
Posted: 2017-07-13T09:10:30-07:00
Hi there,
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:
Secondly, and far worse, is that at random times, the converted file only contains about 1/3 of the image - the rest is grey. I just went through the logs and found that it seems to only be processing these pictures once (I was thinking it might be processing them multiple times). I also thought maybe it was a concurrency issue (especially since I'm not much versed in parallel programming and it has been a long time since I did much coding at all), but I thought the file system would take care of that. Other files in the same folder process fine. There is a significant size difference in the resulting files with the corrupted files typically around 300 KB, the properly compressed files about 1-3 MB and the original files around 5-6 MB.
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
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