This question is an extension to Infragistics BarcodeReder strange behaviour.
While I got my question solved in the previous question then the barcode reader control still behaves strange.
I have been trying to fix this, but somehow it's like it doesn't really want what I want.
To explain the problem short then it is like this:
1st approach:I have a file watcher which is starting a background worker every time there is a new file in a certain folder.This background worker uses Infragistics BarcodeReader to decode a QR code.
This works good when there is only one new file in the folder at a time.
As soon as there are more than one file then a System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it. is thrown at _barcodeReader.Decode(BitmapFromUri(new Uri(_fullPath))); . And the strange thing is that this exception is not thrown for all files, but only some of them. And every time it is another amount of exceptions.
ExpceptionMessage: The calling thread cannot access this object because a different thread owns it.ExceptionBody: System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it. at System.Windows.Threading.Dispatcher.VerifyAccess() at System.Windows.Media.Imaging.BitmapSource.get_DpiX() at Infragistics.Controls.Barcodes.ImageProcessing.CreateImageFromPixelsArray(Byte data, ImageData imageData, Boolean isImageZoomed) at Infragistics.Controls.Barcodes.BarcodeReader.Decode(BitmapSource bitmap, Symbology symbologyTypes) at QrDecoderWpf.MyBarcodeReader.DecodeQr() in C:\Users\nawed\Desktop\WorkSpaceVS\TestApplication\QrDecoderWpf\MyBarcodeReader.cs:line 50
With this approach 50% of the QR codes were not giving any result and there were around 10% exceptions
2nd Approach:This approach is not creating a background worker, and is using BarcodeReader directly to decode QR.This approach is very slow and time consuming, therefor I prefer the 1st approach with the background worker.With this approach there were no exceptions and the amount of QR codes decoded were around 90-95%, but around 10% of those 90% had a very strange code like 025, 343, 23425,25266 or 2525. Normally all our QR codes are formatted like DDCCDDDDDDDD.DDD.DD where D = digit (0-9) and C = character (A-Z).
This has frustrated me for very long time now, I hope you guys can help me out.
Thanks in advance!
A sample project with PDF's can be found here https://we.tl/hnKOJBjQ9R (Link available untill 24 November 2016)
I was able to reproduce your exception with the sample provided. I was also able to reproduce the exception in my own simplified sample. As a result I have logged a development issue for this. The ID for that dev issue is 229007. I also created a private support case for you where I have linked the dev issue to. This will allow us to automatically notify you when the issue is resolved and available for download in a service release. The case number is CAS-179039-Z9F5P3.
While we resolve this issue in the product, I recommend that you try using the DecodeAsync method instead of calling Decode inside of a background thread. The current issue is that we have some static elements inside the BarcodeReader that are used when you call Decode() and these static elements are not thread safe. If you use DecodeAsync() however you can avoid this. It may not be the solution for your application but for now it's the only way to get around this crash.
As for long decode times when doing this synchronously, I recommend trying to crop the image so that it only includes the barcode you are trying to read. Based on the 400 dpi setting you set in the inkspace export command the image is probably very large and the BarcodeReader needs to examine the whole thing looking for a barcode. This will take some time. You can speed this up a little by only providing the BarcodeReader with the QR code portion. This image should be a lot smaller than a full page PDF at 400 dpi.
thanks for your reply.
I had some time to do some testing regarding the async method and cropping pictures. While the Async method helps with the Exception then I have an issue with the cropping. My problem is that I never know where the QR code is located on a page. Basically that is why I used the whole page for decoding.
and regarding to lower the DPI of the PDF to PNG, well it seems like the lower I go in DPI, the less the barcode reader detects. Below I have some statistics about how it went with different DPI's: (There has been 3 tests with each DPI, with the same 88 PDF-files)
All of those QR's I have scanned with another QR-Reader (https://play.google.com/store/apps/details?id=com.google.zxing.client.android, with my phone) and they all work, regardles of the DPI.