daniel-lerch / vocup

Vocabulary trainer.
https://www.microsoft.com/p/vocup/9n6w2h3qjqmm
GNU Affero General Public License v3.0
9 stars 3 forks source link

Crash when closing multiple program instances at once #36

Closed megabugman closed 2 years ago

megabugman commented 3 years ago

to reproduce:

  1. open many instances
  2. right click on the task bar icon and select "close all windows" -> crash

potential solution: allow only one instance

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

** Exception Text ** System.IO.IOException: The process cannot access the file 'C:\Users\Noname\AppData\Local\VectorData\Vocup.exe_Url_c2sx0hgu15odnosfwq34l2zmko4ish25\1.8.2.0\user.config' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Configuration.Internal.WriteFileContext.FileIsWriteLocked(String FileName) at System.Configuration.Internal.WriteFileContext.ReplaceFile(String Source, String Target) at System.Configuration.Internal.WriteFileContext.Complete(String filename, Boolean success) at System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions) at System.Configuration.ClientSettingsStore.ClientSettingsConfigurationHost.WriteCompleted(String streamName, Boolean success, Object writeContext) at System.Configuration.UpdateConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext) at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll) at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings) at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values) at System.Configuration.SettingsBase.SaveCore() at System.Configuration.SettingsBase.Save() at System.Configuration.ApplicationSettingsBase.Save() at Vocup.MainForm.StoreSettings() in C:\Users\Daniel Lerch\source\vocup\src\Vocup\MainForm.cs:line 150 at System.Windows.Forms.Form.OnFormClosing(FormClosingEventArgs e) at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

daniel-lerch commented 3 years ago

This is a very tricky bug. Sharing configuration and even opened vocabulary books between multiple processes is way too complicated for a small project like Vocup. There should be definitely only one process running at a time. If users want to have a feature like in Microsoft Office to open multiple windows on the same document they should open a new issue.

Approaches to consider for making Vocup a single instance application:

Twometer commented 2 years ago

An easy solution to this could be to just catch the IOException, and just ignore the error - you'd only save the settings for one of the windows (but what else should it do, anyways), and save you the effort of creating a cross-platform capable IPC system