WinDynamicDesktop icon indicating copy to clipboard operation
WinDynamicDesktop copied to clipboard

System.IO.IOException

Open otavio-silva opened this issue 7 years ago • 10 comments

System.IO.IOException: Process couldn't access "C:\...\AppData\Local\Packages\38719TimothyJohnson.WinDynamicDesktop_rfarkse4rn21a\LocalState\settings.conf" because it's been used in another process.

I don't actually know if this error causes something serious or not, but still I will report it.

  • Steps to reproduce it: It appears randomly

  • Screenshots (if applicable): image_log

  • Log file (if it exists, see here for how to find it): System.IO.IOException: O processo não pode acessar o arquivo 'C:\Users\otavi\AppData\Local\Packages\38719TimothyJohnson.WinDynamicDesktop_rfarkse4rn21a\LocalState\settings.conf' porque ele está sendo usado por outro processo. em System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) em 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) em System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) em System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) em System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) em System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost) em System.IO.File.WriteAllText(String path, String contents) em WinDynamicDesktop.JsonConfig.<>c__DisplayClass4_0.<SaveConfig>b__0() em System.Threading.Tasks.Task.InnerInvoke() em System.Threading.Tasks.Task.Execute() --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada --- em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) em WinDynamicDesktop.JsonConfig.<SaveConfig>d__4.MoveNext() --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada --- em System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)

  • Windows version (e.g. 7, 10): Windows 10 Education 1809

  • WinDynamicDesktop version (e.g. 2.0.0): 3.0.0 (UWP)

  • Installation source (e.g. installer, Microsoft Store, portable EXE): Microsoft Store

otavio-silva avatar Jan 21 '19 14:01 otavio-silva

Something is using some of the files needed for the program to work. Try opening task Manager and closing the process WinDynamicDesktop UPD: or maybe you should run the program as an administrator

P.s. try the GitHub version: https://github.com/t1m0thyj/WinDynamicDesktop/releases/tag/v3.0.0

MD-DeCode avatar Jan 22 '19 15:01 MD-DeCode

There shouldn't be a problem with using the Windows Store version or needing admin privileges. There is a bug in the app currently where in some cases the settings file could potentially be locked by WinDynamicDesktop when it tries to save it to disk. This will be fixed in the next version.

t1m0thyj avatar Jan 22 '19 15:01 t1m0thyj

I uninstalled the version from Microsoft Store and used the GitHub Setup.exe and the problem seems to be gone now

otavio-silva avatar Jan 26 '19 18:01 otavio-silva

pfff

MD-DeCode avatar Jan 27 '19 08:01 MD-DeCode

I have github version, v3.0.0, got the same exception. Got it after system wake (mby this is the reason).

benchdoos avatar Jan 28 '19 07:01 benchdoos

@t1m0thyj Isn't it the problem with https://github.com/t1m0thyj/WinDynamicDesktop/blob/034f1f8021c6171ac78f0f1da4ca240a572063fd/src/JsonConfig.cs#L61

I believe it should be File.WriteAllTextAsync("settings.conf", newJson)); Now, when Task.Run borrows a new thread from a thread pool, it most probably interferes with some locks made by previous thread. We can reuse existing thread for writing.

Then the function reading the config would become:

public static Task void SaveConfig()
        {
            string newJson = JsonConvert.SerializeObject(settings);

            if (newJson != lastJson)
            {
                await File.WriteAllTextAsync("settings.conf", newJson));
                lastJson = newJson;
            }
        }

I can create a pull request. If simultaneous read/writes are necessary then we can utilize ReaderWriterLock

MikelThief avatar Jan 29 '19 10:01 MikelThief

@t1m0thyj Isn't it the problem with WinDynamicDesktop/src/JsonConfig.cs

Line 61 in 034f1f8

await Task.Run(() => File.WriteAllText("settings.conf", newJson)); I believe it should be File.WriteAllTextAsync("settings.conf", newJson)); Now, when Task.Run borrows a new thread from a thread pool, it most probably interferes with some locks made by previous thread. We can reuse existing thread for writing.

Then the function reading the config would become:

public static Task void SaveConfig()
        {
            string newJson = JsonConvert.SerializeObject(settings);

            if (newJson != lastJson)
            {
                await File.WriteAllTextAsync("settings.conf", newJson));
                lastJson = newJson;
            }
        }

I can create a pull request. If simultaneous read/writes are necessary then we can utilize ReaderWriterLock

Create a pull request and t1m0thyj then look at the changes

MD-DeCode avatar Jan 31 '19 13:01 MD-DeCode

@FantasiaChan I will make tests over the weekend with my custom version to see if this causes an issue

MikelThief avatar Jan 31 '19 15:01 MikelThief

@MikelThief AFAICT File.WriteAllTextAsync is only available in .NET Core so I can't use it. I believe I've fixed the issue in my latest commit thru making use of SemaphoreSlim.

t1m0thyj avatar Feb 04 '19 15:02 t1m0thyj

This should be fixed in version 3.1 which was just released (will take a day or two to show up on the Microsoft Store).

t1m0thyj avatar Mar 06 '19 04:03 t1m0thyj