ThreadLocal issue when closing application
Posted: Thu Jun 17, 2021 7:53 am
Hi,
There is a class A, in the destructor of which some function is called, which in turn uses the AScan function. The application (MDI) creates an object (instance) of class A in one of its windows and does not explicitly destroy it (this is not necessary). This object will be destroyed when GC is called. When the application (MDI) is closed, the destructor is called on the instance of class A. Then it comes down to the AScan function, and it throws an ObjectDisposedException with a ThreadLocal object specified. As I understand it, ThreadLocal is used in RuntimeState.
Why is the ThreadLocal disposed before there are any objects that have not yet been destroyed that can use it?
P.S. The problem occurs in a real application. I tried to create a situation in a small test application, but the problem did not appear there.
Best regards,
Leonid
There is a class A, in the destructor of which some function is called, which in turn uses the AScan function. The application (MDI) creates an object (instance) of class A in one of its windows and does not explicitly destroy it (this is not necessary). This object will be destroyed when GC is called. When the application (MDI) is closed, the destructor is called on the instance of class A. Then it comes down to the AScan function, and it throws an ObjectDisposedException with a ThreadLocal object specified. As I understand it, ThreadLocal is used in RuntimeState.
Why is the ThreadLocal disposed before there are any objects that have not yet been destroyed that can use it?
P.S. The problem occurs in a real application. I tried to create a situation in a small test application, but the problem did not appear there.
Best regards,
Leonid