Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipstears/994963 to your computer and use it in GitHub Desktop.
Save philipstears/994963 to your computer and use it in GitHub Desktop.
Release and Swap a COM reference
<Extension()>
Public Sub ReleaseAndExchange(Of T As Class)(ByRef oldComObject As T, ByVal newComObject As T)
If oldComObject IsNot Nothing Then
Marshal.ReleaseComObject(oldComObject)
End If
oldComObject = newComObject
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment