weto91 / kindle-cover-fixer

Fix your e-book covers in your Kindle device
GNU General Public License v3.0
26 stars 4 forks source link

Program Crashes on Startup with System.InvalidOperationException #18

Open scottbright22 opened 10 months ago

scottbright22 commented 10 months ago

Program is getting System.InvalidOperationException on my Kindle Scribe. It seems like it's a threading problem and might need a semaphore. Changing the timer to 10 seconds gets around the issue.

This Code Gets it to Work Again:

    private void CheckKindle()
    {
        CheckKindleType(); //New
        Timer aTimer = new(10000); //Changed
        aTimer.Elapsed += OnTimedEvent!;
        aTimer.AutoReset = true;
        aTimer.Enabled = true;
    }

System.InvalidOperationException HResult=0x80131509 Message=Collection was modified; enumeration operation may not execute. Source=System.Private.CoreLib StackTrace: at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() at System.Collections.Generic.List`1.Enumerator.MoveNext() at Kindle_Cover_Fixer_V2.MainWindow.IsOnKindleScribe() in D:\VS_Source\kindle-cover-fixer-main\Kindle Cover Fixer V2\LibraryCheckKindle.cs:line 60 at Kindle_Cover_Fixer_V2.MainWindow.IsOnKindlePreparation() in D:\VS_Source\kindle-cover-fixer-main\Kindle Cover Fixer V2\LibraryCheckKindle.cs:line 41 at Kindle_Cover_Fixer_V2.MainWindow.FindBooksTask() in D:\VS_Source\kindle-cover-fixer-main\Kindle Cover Fixer V2\FindBooks.cs:line 17 at System.Threading.Thread.StartHelper.Callback(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)