Can ThreadStatic IDisposable be automatically deleted?

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 ThreadStatic graphics (which was created from an image) to measure text size. Now, I am faced with the problem that from time to time the graph seems to be deleted, because even reading the TextRenderingHint property fails (throws an ArgumentException).

Is there any mechanism that provides graphics, for example. if the flow is idle for a long period?

+4
source share
1 answer

If the thread decays completely, the ThreadStatic object for this thread can be assembled.

The GC will not invoke Dispose directly, but if the object has a “backup” finalizer to clean up after itself, then the GC should invoke this at some point during the collection process.

+9
source

Source: https://habr.com/ru/post/1335106/


All Articles