whistyun / MdXaml

Markdown for WPF - alternate version of Markdown.Xaml
MIT License
245 stars 37 forks source link

Fix dispatcher problems #83

Closed boelew closed 9 months ago

boelew commented 10 months ago

This library assumes that there is a single UI thread in the application. Therefore, Application.Current.Dispatcher gives you always access to the UI thread of your window and is therefore a sufficient solution when you want to have lazy loading for images. In our application however, we have multiple windows with their own UI thread and therefore their own dispatcher. To allow lazy loading we should be able to pass our own dispatcher to the library. This would require much more changes. So therefore we like be able to disable lazy loading and load images directly on the UI thread. Then we can apply any changes to the MarkdownScrollViewer via our own dispatcher.

For base64 images this fixed our problems. When testing images from an URL I found that the application would hang due to the GetAsync method of the HttpClient. It turned out that we had to apply ConfigureAwait(false) to run all code after the await on the same thread. This fixed the hanging application (deadlock).

For reference, I work together with Luke Ordelmans who created a PR earlier on your project: https://github.com/whistyun/MdXaml/pull/82

Please, if you agree with this change, then I would kindly ask you to create a new NuGet package as well.

whistyun commented 9 months ago

We releases v1.24.0. Please wait until validation on nuget.org is complete.

boelew commented 9 months ago

Thank you!