rlv-dan / PhotoSift

Quickly organize unsorted images into folders using the keyboard
GNU General Public License v3.0
47 stars 8 forks source link

frequent exceptions undoing move operations #4

Closed carfesh closed 4 years ago

carfesh commented 5 years ago

Hi,

for me, when undoing a move operation, I will frequently receive exceptions that the restored file cannot be opened (Win10 1809 with latest patches). I've looked a bit into it, when this happens the console contains output like (sorry for the German language output, don't have an Englisch system at hand right now):

ImageCache ERROR: System.IO.IOException: Der Prozess kann nicht auf die Datei "blabla.jpg" zugreifen, da sie von einem anderen Prozess verwendet wird.
   bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   bei System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
   bei PhotoSift.ImageCache.LoadImage(Object data) in E:\i386\Users\torsten\Desktop\kurros-PhotoSift\PhotoSift-master\PhotoSift\ImageCache.cs:Zeile 108.

I believe what is happening is that the antivirus is still scanning/thus locking the restored file when PhotoSift attempts to read it (ReadAllBytes).

I've implemented a workaround for this by adding a minor delay after restoring the file, like in the following commit:

https://github.com/carfesh/PhotoSift/commit/92bd192fb2d380235a226575a1a4d0ea6358085a

It's not nice, but for me it seems to work.

Is PhotoSift still being maintained?

If you have a better idea for a proper fix, that would be great; I've thought about implementing a retry mechanism, but I'm not a C# coder..

Kind regards, Torsten

rlv-dan commented 5 years ago

Hi,

I will have a look at this when I make the next version! Does your fix work 100%?

carfesh commented 5 years ago

For me the fix seems to work 100%; I haven't had a single instance since I fixed it. These exceptions occurred quite frequently, and PhotoSift then only showed an error message in the GUI about not being able to load the image. Just to emphasize it, for me it only happens right after undo operations, when the restored file is attempted to load immediately. Every normal move, copy, etc did not exhibit this for me, or at least I haven't encountered it.

This disappeared completely with that workaround, but it still feels like an ugly hack; I would rather do something like trying to open it, and only if it fails retry it like every 100msec until it either worked or failed after 10 retries or something.

I'm not familiar enough with C# however to implement that myself :(

Glad to hear that you will take a look at it, and thanks BTW for a very useful small tool, I came to appreciate the simpleness for quickly sifting through a bunch of images!

carfesh commented 5 years ago

A small update: I had an instance today where the previous workaround still produced an error, as the 100 msec were not sufficient. I went ahead and implemented a workaround that hopefully will work better.

It will now only delay if the image failed to load the first time, and then retry for 10 times. At least I hope that that's what it'll do..

I've committed it here:

https://github.com/carfesh/PhotoSift/commit/b22a4d65c309f5a6ef71de4d36929ba6e8024e4b

carfesh commented 4 years ago

Just an update: with that newer fix I could no longer reproduce the error. Current builds of PhotoSift still have this issue, so I would appreciate it if a solution could find its way into the code :)

rlv-dan commented 4 years ago

FYI I have merged your fix into master. There will be a new release soon!