Can a ThreadStatic IDisposable be automatically disposed?

一个人想着一个人 提交于 2020-01-10 19:53:08

问题


This is not a question of how to automatically call dispose - my problem is the opposite: I have a thread pool where each thread has a ThreadStatic Graphics (which was created from an Image) to perform text size measuring. Now I've ran into the problem that from time to time the graphics seems to be disposed as even reading the TextRenderingHint property fails(causes an ArgumentException).

Is there some mechanism which disposes the Graphics e.g. if the thread is idle for a long period?


回答1:


If the thread dies completely then the ThreadStatic object for that thread can be collected.

The GC won't call Dispose directly, but if the object has a "fallback" finaliser to clean-up after itself then the GC should call that at some point during the collection process.



来源:https://stackoverflow.com/questions/4658934/can-a-threadstatic-idisposable-be-automatically-disposed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!