falahati / WindowsDisplayAPI

WindowsDisplayAPI is a .Net wrapper for Windows Display and Windows CCD APIs
GNU Lesser General Public License v3.0
104 stars 21 forks source link

fix(finalizer): pass IntPtr instead of SafeHandle in finalizer #21

Closed Hoffs closed 1 year ago

Hoffs commented 1 year ago

This fixes usage of SafeHandle that is being disposed/was disposed in the finalizer to call external function. Passing the SafeHandle wrapped object fails as it is disposed already and SafeHandleAddRef throws an exception while performing interop.

See similar SO issue: https://stackoverflow.com/a/47940095

I have been running a program with this fix and have not it crash for over a day, where as previously it would fail after an hour or two.

falahati commented 1 year ago

Thanks @Hoffs looks ok to me