Monday, December 31, 2007

objectdisposedexception - Safe handle has been closed Pt. 2

In doing some more research, I found this bit from a Microsoft Feedback page:


The issue reported to us occurs not because the iDB2NamedEvent class calls the Handle property, but because it calls it while the WaitHandle is registered with the ThreadPool through ThreadPool.RegisterWaitForSingleObject. This is not a valid operation.

The workaround is either to avoid closing the handle manually in the finalizer for the iDB2NamedEvent class (the runtime will take care of that anyway), or unregister the WaitHandle from the ThreadPool before closing the handle. Option 1 is probably preferable.


It sounds like this is the only case that you should not call the disposed method. Instead, let program clean it up on it's own. Yuck.

No comments: