Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save philipstears/994963 to your computer and use it in GitHub Desktop.

Select an option

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