-
Notifications
You must be signed in to change notification settings - Fork 34
Win32Exception is thrown when WPF runs out of internal resources #1
Comments
Here is another manifestation of what I believe is the same bug:
|
This library is great, but using it from any random thread is simply not possible because of it's dependency on WPF components. WPF components must be run from a thread that is properly initialized as STA and running a proper dispatcher message pump due to the way they schedule themselves for resource cleanup. I have explained this before on StackOverflow and provided an implementation of a In the end, this library will either need to hide these details by executing the work on its own internally managed Dispatcher thread pool and simply handing back Tasks that the caller can wait on, or it can pass that burden onto the caller. I would suggest the former, but it will require changes to the API to return Tasks that can be awaited. I don't think this is a radical change in today's landscape since almost anyone doing anything with .NET 4.5 is probably working with async APIs now. Great API, so I wish you luck with the changes! Let me know if you'd like any further details on the subject. |
That's awesome, thank you - you've filled in some of the blanks in my understanding of WPF and threading. (By the way, the link to your Gist from your SO answer is broken. I assume it should link to this.) What do you think of this answer in the SO question you linked to? If I understand correctly, without using a thread initialized as STA, calling If I wanted to keep the DynamicImage API exactly as-is, do you see a problem with me using your The only problem I can see is in the cases where the DynamicImage API does expose WPF objects externally, such as here and here - I'd need to investigate whether a |
First, thanks for the heads up, I've fixed the Gist link on SO. The problem with simply calling As for waiting on the As for handing back |
Images are created on a thread pool that is controlled by DispatcherTaskScheduler. The Dispatcher infrastructure is only started on these threads, whereas previously the Dispatcher infrastructure would have been started on all ASP.NET that requested DynamicImage to create an image. This is a possible fix for #1, but needs more testing. It also involves several breaking API changes, so a decision will have to be made whether to stick to SemVer and release this as v4.0.0.
After an AppDomain has been up for a while, DynamicImage sometimes fails to generate an image because of an exception thrown by WPF:
This looks to be related to the
Dispatcher
creating internalHwndWrapper
objects. There is an SO question and answer here, which suggest thatDispatcher
s need to be cleaned up:http://stackoverflow.com/questions/8995588/asp-net-throws-win32exception-when-creating-bitmapimage-cannot-find-file-specif
DynamicImage doesn't explicitly create threads, so there is nowhere obvious to plug that code in. Perhaps DynamicImage could maintain its own thread pool and do all image generation on one of those threads.
The text was updated successfully, but these errors were encountered: