FantasticFiasco / mvvm-dialogs

Library simplifying the concept of opening dialogs from a view model when using MVVM in WPF
Apache License 2.0
659 stars 77 forks source link

Bug/fix invalid operation exception with multi threading #266

Closed HeedfulCrayon closed 1 year ago

HeedfulCrayon commented 1 year ago

Description

Made the DialogService capable of spanning multiple STA threads.

Checklist

FantasticFiasco commented 1 year ago

Got hung up on other things but am back. Am focusing on the implementation using the concurrent dictionary. To bad there isn't a thread safe list instead, we now introduce some situations where previously we threw an error if we failed to modify the registered views where we now instead only log. I'll look more on this during the weekend.

Btw, thank you for your patience, I haven't been able to dedicate the time this requires.

FantasticFiasco commented 1 year ago

I refactored the code to use a simple locked list instead of the concurrent dictionary. The list is slower but I hope this is insignificant since registering and unregistering views doesn't happen that often, however I haven't benchmarked it. I was hesitant to use the dictionary since it introduced new behaviors where it logged the errors instead of plainly crashing the application.

Thank you for bringing this issue to my attention, and for contributing the actual fix, that is just awesome!

I've updated CHANGELOG.md to highlight that it was a contribution from you.