Improve implementation of async methods
Svarr opened this issue · 0 comments
Svarr commented
Is your feature request related to a problem? Please describe.
In reference to #154, if I deactivate the plugin and proceed with the reproduction steps without restarting MusicBee first, it will freeze nonetheless. The errors, that get logged after the necessary termination of MusicBee via the task manager, suggest that some tasks were still running and not ended along with the program.
Describe the solution you'd like
- Add a mechanic to all async tasks that allows for premature termination (e.g. in case of plugin deactivation, program termination, errors, etc.)
- Make the plugin more robust by adding exception handling (see below) both within the async tasks and to the code that uses them, and by adding timeouts to guarantee their termination
Additional context
The following exception was caused by forcibly closing MusicBee via the task manager:
21.07.2022 17:34:45 - 10.0.19044.0 - 3.4.7805.33439D - System.ObjectDisposedException: Cannot access a disposed object.
Object name: '#=zziapYCHkKIL0B5EplaYmmhGl87_u'.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at #=zsSqWEB_uCfYs1RIo5gmlWEiXxs7c.#=zp1Dcr9I=(Delegate #=zsfBhVjI=, Object[] #=zHv5cMh8=)
at #=zyvHJtEjiqYExjkuDDkMB0$E=.#=ztX$YAEXYEP4D(#=zDS75MM6CY57FAu1dYwKk3w0= #=zC_RZ8VY=, #=zOwbXrBNreBGuMkm1cSHSgOk= #=zqh3ZSeJUwsH0, Boolean #=zd9HOE2Ek70Uerh3EZA==, Boolean > #=zrRlgWConwe0mghL1myQLn7Ep9_pJ)
The following exception was most likely thrown at some point after the imgur album was changed (see #153) but may be unrelated to this issue:
21.07.2022 17:05:30 - 10.0.19044.0 - 3.4.7805.33439D - System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.Http.HttpRequestException: Request failed with status code ExpectationFailed
at RestSharp.ResponseThrowExtension.ThrowIfError(RestResponse response)
at RestSharp.RestClient.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RestSharp.RestClientExtensions.<ExecuteAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RestSharp.RestClientExtensions.<PostAsync>d__16`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MusicBeePlugin.ImgurClient.ImgurClient.<UploadImage>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MusicBeePlugin.DiscordTools.Assets.Uploader.ImgurUploader.<UploadAsset>d__12.MoveNext()
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.Net.Http.HttpRequestException: Request failed with status code ExpectationFailed
at RestSharp.ResponseThrowExtension.ThrowIfError(RestResponse response)
at RestSharp.RestClient.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RestSharp.RestClientExtensions.<ExecuteAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RestSharp.RestClientExtensions.<PostAsync>d__16`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MusicBeePlugin.ImgurClient.ImgurClient.<UploadImage>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MusicBeePlugin.DiscordTools.Assets.Uploader.ImgurUploader.<UploadAsset>d__12.MoveNext()<---