Disconnecting iTunes COM

168 views Asked by At

I'm currently working with the iTunes COM with .NET, and something I came across previously, which stopped me using it, has happened again and I can't for the life of me figure it out.

When I go to close iTunes during or after my program has closed, it tells me something is still using the "Application Scripting Interface", COM is still connected.

This is what I have (removed what is not required)

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
         AddHandler itunes.OnAboutToPromptUserToQuitEvent, AddressOf itunes_OnAboutToPromptUserToQuitEvent
    End Sub

    Private Sub itunes_OnAboutToPromptUserToQuitEvent()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(itunes)
    End Sub

So, the above code does disconnect the COM to the extent that I need to restart iTunes to use it again, but, it doesn't get rid of the Application Scripting error. Meaning, I still need to click quit after the error dialog comes up. Everything else works fine, apart from this.

Any idea?

-- I've had a look at other questions that had this issue, but none of them resolved it for me. I'm not sure if the event doesn't work anymore with this current version of iTunes, but, it doesn't seem to work currently either way.

1

There are 1 answers

0
Rabtok On

Had same issue with COM and Office, this solved it;

  While System.Runtime.InteropServices.Marshal.ReleaseComObject(itunes) <> 0
            Application.DoEvents()
        End While