views:

263

answers:

0

I'm at a total loss of what to do. I am using an AxWindowsMediaPlayer object that is created programatically and added to the form's controls:

Private Sub PlayNext(ByVal path As String)
    Dim wA As Rectangle = Screen.PrimaryScreen.Bounds
    Dim vidPlayer As New AxWMPLib.AxWindowsMediaPlayer

    Controls.Add(vidPlayer)
    With vidPlayer
        .uiMode = "none"
        .Width = wA.Width
        .Height = wA.Height
        .URL = path
        .enableContextMenu = False
        AddHandler .PlayStateChange, AddressOf playstatechange

        .Ctlcontrols.play()
    End With  
End Sub

Private Sub playstatechange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent)
    Select Case e.newState
        Case WMPLib.WMPPlayState.wmppsMediaEnded
            Dim vidPlayer As AxWMPLib.AxWindowsMediaPlayer = CType(sender, AxWMPLib.AxWindowsMediaPlayer)
            Using vidPlayer
                Controls.Remove(vidPlayer)
            End Using
    End Select
End Sub

This code works flawlessly... for a while. This app is running on a dedicated machine for extended periods of time, running the PlayNext() procedure every minute or so on a dedicated thread. And then randomly I get a System.AccessViolationException. Sometimes it is 5 minutes into running, sometimes 8 hours. It doesn't seem to happen on my Windows 7 development machine (running WMP 12) as I left it running in debug mode hoping to catch more on the exception for around a week, exception free. The machine it is deployed on is running XP Pro SP3 (WMP 11). When it bombs out I only get the 'has encountered a problem and needs to close' window. When I click on the 'what does this error report contain' link, it tells me the faulting module is wmp.dll. I added some code to log more on the exceptions by adding handlers for Application.ThreadException and AppDomain.CurrentDomain.UnhandledException. Here's the full exception that gave me:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at MirrorImage.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 78

The last line (in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 78) has only recently shown up in the last couple of crashes.

I stumbled across a few article similar to this: http://msdn.microsoft.com/en-us/library/system.accessviolationexception.aspx#CommunityContent that claim the DEP (Data Execution Prevention) could be the issue. I tried disabling that (using EditBin.exe on the final .exe, and through the machine's control panel specifically targeting my app) with no luck.

Any help would be appreciated, I can provide more details if needed. Thanks!