plneto / Synology.Api.Client

.NET/C# client for the Synology API
MIT License
21 stars 13 forks source link

Fix a deadlock when running in UI thread #12

Closed FroggieFrog closed 1 year ago

FroggieFrog commented 1 year ago

The current version does produce a deadlock when used in a UI thread. This PR fixes fixes that issue.

I tested this with a WinForms (.NET 4.8 and .NET 7) and a MAUI (.NET 7) app. When running inside a Console app (.NET 7) everything worked for me.

It is not a nice solution but works.

More information: https://blog.stephencleary.com/2013/01/async-oop-2-constructors.html

Proper solution: Factory pattern

Used Hack that works: https://stackoverflow.com/questions/23048285/call-asynchronous-method-in-constructor#comment55917952_28737702

plneto commented 1 year ago

Thank you