windows handles going berserk!

Apr 28, 2010 at 3:03 AM

Hi Jer

I have hooked up the MediaUriElement and although it displays the video clips quite well... I am noticing a jump in windows handles.. after about 5 mins it is over 10000.

I have the MUE in a seperate usercontrol which I dispose of and recreate every time i play a file and then call a gc.collect ... however no joy.

Do you have any suggestions?

Imports System.IO
Imports System.Data
Imports System.Threading
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports WPFMediaKit
Imports WPFMediaKit.DirectShow.Controls

' Interaction logic for Player.xaml
Partial Public Class Player
    Inherits System.Windows.Controls.UserControl
    Implements IDisposable

    Private mMedia As WPFMediaKit.DirectShow.Controls.MediaUriElement
    'Private mPicture As Picture
    'Private mSmartArt As SmartArt

    Private mArea As String = "Full"
    Private mOrientation As String = "Landscape"

    Private mMediaType As String = ""
    Private mWidth As Integer = 0
    Private mHeight As Integer = 0
    Private mQueueID As String = ""
    Private mFileID As String = ""

    Private mIndex As Integer = 0

    Private mState As PlayerStates = PlayerStates.idle
    Private mVolume As Integer = 100
    Private mDuration As Integer = 20
    Private mLastStartTime As Date = Now.AddDays(-1)

    Delegate Function ProcessCB() As Integer

    Public Sub New()
        InitializeComponent()
    End Sub
    Public Sub Create(ByVal Index As Integer, ByVal AudioDevice As Integer, ByVal Speaker As Integer, ByVal Volume As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Orientation As String, ByVal Area As String)

        mWidth = Width
        mHeight = Height
        mIndex = Index
        mVolume = Volume
        mOrientation = Orientation
        mArea = Area

    End Sub

    Public Function LoadFile(ByVal QueueID As String, ByVal FileID As String, ByVal mediaFile As String, ByVal Volume As Integer, ByVal Duration As Integer) As Boolean

        mFileID = FileID
        mVolume = Volume
        mQueueID = QueueID
        mDuration = Duration

        Dim Ext As String = Path.GetExtension(mediaFile).ToUpper
        Select Case Ext
            Case ".JPG", ".BMP", ".GIF", ".TIF", ".PNG"
                'mMediaType = "Picture"
                'Try
                '    mPicture = New Picture
                '    mPicture.LoadFile(mediaFile, mDuration)
                '    Panel.Children.Add(mPicture)
                '    Return True
                'Catch ex As Exception
                'End Try

            Case ".MP3", "WMA", ".MPG", ".DAT", ".AVI", ".WMV"
                mMediaType = "Media"
                Try
                    mMedia = New MediaUriElement
                    mMedia.BeginInit()
                    mMedia.Source = New System.Uri(mediaFile)
                    mMedia.Volume = 0
                    Panel.Children.Add(mMedia)
                    mMedia.EndInit()

                    GC.Collect(2)
                    GC.WaitForPendingFinalizers()
                    GC.Collect(2)

                    Return True
                Catch ex As Exception
                    InsertLogEntry("1", "MyViewer", "Player " & mArea, "LoadFile", "ex", "Media " & ex.Message)
                End Try

            Case ".DLL"
                'mMediaType = "SmartArt"
                'Try
                '    mSmartArt = New SmartArt
                '    mSmartArt.Create(mOrientation, mWidth, mHeight)
                '    Dim DB As DB = New DB(oSockSets.LanServer, "Media", "flexinet", "s3cr3t")
                '    mSmartArt.LoadFile(mediaFile, mArea, DB.ExecLookup("SELECT Properties FROM Adverts Where Id=" & mFileID))
                '    DB.Close()
                '    DB.Dispose()
                '    DB = Nothing
                '    Panel.Children.Add(mSmartArt)

                '    Return True
                'Catch ex As Exception
                'End Try
        End Select
        Return False

    End Function

    Public Function Process() As Integer
        Return Me.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, New ProcessCB(AddressOf ProcessPlayer))
    End Function

    Public Function ProcessPlayer() As Integer
        Select Case mMediaType
            Case "Picture"
                'mState = mPicture.Process()
            Case "Media"
                mState = IIf(mMedia.IsPlaying, PlayerStates.playing, PlayerStates.finished)
                If mState = PlayerStates.finished Then
                    mMedia.Close()
                End If
            Case "SmartArt"
                'mState = mSmartArt.Process()
        End Select
        Return mState
    End Function

    Public Sub PlayerStart()
        Select Case mMediaType
            Case "Picture"
                'mPicture.PlayerStart()
            Case "Media"
                mMedia.Play()
            Case "SmartArt"
                'mSmartArt.PlayerStart()
        End Select
        mLastStartTime = Now
    End Sub

    Public WriteOnly Property IsPaused() As Boolean
        Set(ByVal value As Boolean)
            Select Case mMediaType
                Case "Media"
                    Try
                        If value Then
                            mMedia.Stop()
                        Else
                            mMedia.Play()
                        End If
                    Catch ex As Exception
                    End Try
                Case "Picture"
                Case "SmartArt"
            End Select
        End Set
    End Property

    Public ReadOnly Property IsFading() As Boolean
        Get
            Return Now.Subtract(mLastStartTime).TotalSeconds < 10
        End Get
    End Property

    Public ReadOnly Property MediaType() As String
        Get
            Return mMediaType
        End Get
    End Property

    Public Sub Reset()

        If Not mMedia Is Nothing Then
            mMedia.Close()
            mMedia = Nothing
        End If

        'If Not mPicture Is Nothing Then
        '    mPicture.Dispose()
        '    mPicture = Nothing
        'End If

        'If Not mSmartArt Is Nothing Then
        '    mSmartArt.Dispose()
        '    mSmartArt = Nothing
        'End If

    End Sub

#Region " IDisposable Support "

    Private disposedValue As Boolean = False        ' To detect redundant calls
    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                'Reset()
            End If
            ' TODO: free shared unmanaged resources
        End If
        Me.disposedValue = True
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region


End Class

  

Imports System.Threading
Imports System.Data
Imports System.IO
Imports System.Reflection
Imports System.Windows.Media.Animation

Imports System.Windows.Media.Effects
Imports TransitionEffects
Imports System.Windows.Media

'Imports J832.Common
'Imports Microsoft.Samples.KMoore.WPFSamples.Transition
'Imports Transitionals

'Imports FluidKit.Controls ' Microsoft.Samples.KMoore.WPFSamples.Transition

' Interaction logic for BPlayer.xaml
Partial Public Class Players
    Inherits System.Windows.Controls.UserControl
    Implements IDisposable

    Private mArea As String = ""
    Private mPlayerType As String = ""
    Private mOrientation As String = "Landscape"
    Private mQueueID As String = ""

    Private mAudioDevice As Integer = 0
    Private mSpeaker As Integer = 0
    Private mVolume As Integer = 0
    Private mDuration As Integer = 0

    Private mWidth As Integer = 0
    Private mHeight As Integer = 0

    'Private mTrans As TransitionList

    Private mPlayer1 As Player
    Private mPlayerVB1 As Windows.Media.VisualBrush
    Private mPlayer2 As Player
    Private mPlayerVB2 As Windows.Media.VisualBrush
    Private mPlayCounter1 As Integer = 0
    Private mPlayCounter2 As Integer = 0

    Private mCurrentPlayer As Integer = 1

    Private mState As PlayerStates = PlayerStates.idle
    Private mPaused As Boolean = False
    Private mPreLoaded As Boolean = False

    Private mLoading As Boolean = False

    Public Event OnStart(ByVal QueueID As String, ByVal Duration As Integer)
    Public Event OnFinished(ByVal QueueID As String)

    Delegate Function ProcessCB() As Boolean


    Public Sub New()
        InitializeComponent()
    End Sub

    Public Sub Create(ByVal PlayerType As String, ByVal Area As String, ByVal Orientation As String, ByVal Volume As Integer, ByVal AudioDevice As Integer, ByVal Speaker As Integer, ByVal Width As Integer, ByVal Height As Integer)

        Try
            mArea = Area
            mPlayerType = PlayerType

            mWidth = Width
            mHeight = Height

            mVolume = Volume
            mAudioDevice = AudioDevice
            mSpeaker = Speaker
            mPreLoaded = False

            'mTrans = New TransitionList
        Catch ex As Exception
            'RaiseEvent OnStatus("Players Create", ex.Message)
        End Try

        mCurrentPlayer = 1

    End Sub


    Public Sub Destroy()

        'mTrans.Dispose()
        'mTrans = Nothing

        mPlayer1.Dispose()
        mPlayer1 = Nothing
        'System.GC.Collect()

        mPlayer2.Dispose()
        mPlayer2 = Nothing
        'System.GC.Collect()

    End Sub

    Public Function Process() As Boolean
        Return Me.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, New ProcessCB(AddressOf ProcessPlayers))
    End Function

    Public Function ProcessPlayers() As Boolean

        Try
            Dim LastState As PlayerStates = mState
            If mCurrentPlayer = 1 Then
                If Not mPlayer1 Is Nothing Then
                    mState = mPlayer1.Process()
                Else
                    mState = PlayerStates.idle
                End If
            Else
                If Not mPlayer2 Is Nothing Then
                    mState = mPlayer2.Process()
                Else
                    mState = PlayerStates.idle
                End If
            End If
            If LastState <> mState Then
                Select Case mState
                    Case PlayerStates.playing
                        RaiseEvent OnStart(mQueueID, mDuration)
                    Case PlayerStates.finished
                        RaiseEvent OnFinished(mQueueID)
                End Select
            End If
            Return (mState = PlayerStates.playing)

        Catch ex As Exception
            InsertLogEntry("1", "MyViewer", "Players " & mArea, "Process", "ex", ex.Message)
            Return False
        End Try
        Return False

    End Function

    Public Overloads Function LoadFile(ByVal QueueID As String, ByVal FileID As String, ByVal mediaFile As String) As Boolean
        mCurrentPlayer = 1
        mQueueID = QueueID
        mPlayer1.LoadFile(QueueID, FileID, mediaFile, mVolume, 20)
    End Function
    Public Overloads Function LoadFile(ByVal QueueID As String, ByVal FileID As String, ByVal mediaFile As String, ByVal Volume As Integer, ByVal Duration As Integer) As Boolean
        mLoading = True
        mQueueID = QueueID
        Try
            Dim Player As Integer = IIf(mCurrentPlayer = 1, 2, 1)
            If Player = 1 Then
                If Not mPlayer1 Is Nothing Then
                    mPlayer1.Reset()
                    mPlayer1.Dispose()
                    mPlayer1 = Nothing
                    mPlayerVB1 = Nothing

                    GC.Collect(2)
                    GC.WaitForPendingFinalizers()
                    GC.Collect(2)
                End If

                mPlayer1 = New Player
                mPlayer1.Create(1, mAudioDevice, mSpeaker, mVolume, mWidth, mHeight, mOrientation, mArea)
                mPlayerVB1 = New Windows.Media.VisualBrush(mPlayer1)

                If mPlayer1.LoadFile(mQueueID, FileID, mediaFile, Volume, Duration) Then
                    mPreLoaded = True
                    mLoading = False
                    Return True
                End If
            Else
                If Not mPlayer2 Is Nothing Then
                    mPlayer2.Reset()
                    mPlayer2.Dispose()
                    mPlayer2 = Nothing
                    mPlayerVB2 = Nothing

                    GC.Collect(2)
                    GC.WaitForPendingFinalizers()
                    GC.Collect(2)
                End If

                mPlayer2 = New Player
                mPlayer2.Create(2, mAudioDevice, mSpeaker, mVolume, mWidth, mHeight, mOrientation, mArea)
                mPlayerVB2 = New Windows.Media.VisualBrush(mPlayer2)

                If mPlayer2.LoadFile(mQueueID, FileID, mediaFile, Volume, Duration) Then
                    mPreLoaded = True
                    mLoading = False
                    Return True
                End If
            End If
        Catch ex As Exception
            InsertLogEntry("1", "MyViewer", "Players " & mArea, "LoadFile", "ex", ex.Message)
        End Try

        mLoading = False
        Return False

    End Function

    Public Sub PlayerStart()
        If mPreLoaded Then
            mCurrentPlayer = IIf(mCurrentPlayer = 1, 2, 1)
            If mCurrentPlayer = 1 And mPlayer1 Is Nothing Then

            ElseIf mCurrentPlayer = 2 And mPlayer2 Is Nothing Then

            Else
                Try
                    'Canvas.Effect = Nothing
                    'Dim eff As TransitionEffect = mTrans.GetNextRandom
                    'eff.OldImage = Canvas.Background

                    'If mCurrentPlayer = 1 Then
                    '    mPlayer1.PlayerStart()
                    '    Canvas.Background = mPlayerVB1 '.VisualBrush
                    'Else
                    '    mPlayer2.PlayerStart()
                    '    Canvas.Background = mPlayerVB2 '.VisualBrush
                    'End If

                    'Dim da As DoubleAnimation = New DoubleAnimation(0.0, 1.0, New Windows.Duration(TimeSpan.FromSeconds(3.2)), FillBehavior.HoldEnd)
                    'da.AccelerationRatio = 0.5
                    'da.DecelerationRatio = 0.5

                    'eff.BeginAnimation(TransitionEffect.ProgressProperty, da)

                    'Canvas.Effect = eff


                    Canvas.Children.Clear()
                    If mCurrentPlayer = 1 Then
                        mPlayer1.PlayerStart()
                        Canvas.Children.Add(mPlayer1)
                    Else
                        mPlayer2.PlayerStart()
                        Canvas.Children.Add(mPlayer2)
                    End If


                    mState = PlayerStates.playing

                Catch ex As Exception
                    mState = PlayerStates.finished
                    InsertLogEntry("1", "MyViewer", "Players " & mArea, "PlayerStart", "ex", ex.Message)
                End Try
            End If
        End If

    End Sub

    Public Sub Break()
    End Sub

    Public Sub ShowVideo()
    End Sub


    Public Property IsPaused() As Boolean
        Get
            Return mPaused
        End Get
        Set(ByVal value As Boolean)
            mPaused = value
            If mCurrentPlayer = 1 Then
                mPlayer1.IsPaused = mPaused
            Else
                mPlayer2.IsPaused = mPaused
            End If
        End Set
    End Property

    Public ReadOnly Property IsPlaying() As Boolean
        Get
            Return (mState = PlayerStates.playing)
        End Get
    End Property
    Public ReadOnly Property IsFading() As Boolean
        Get
            If mCurrentPlayer = 1 Then
                Return mPlayer1.IsFading
            Else
                Return mPlayer2.IsFading
            End If
        End Get
    End Property


    Public ReadOnly Property PreLoaded() As Boolean
        Get
            Return mPreLoaded
        End Get
    End Property

    Public ReadOnly Property VisualBrush() As Windows.Media.VisualBrush
        Get
            Return New Windows.Media.VisualBrush(Canvas)
        End Get
    End Property


#Region " IDisposable Support "

    Private disposedValue As Boolean = False        ' To detect redundant calls
    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                Destroy()
            End If
            ' TODO: free shared unmanaged resources
        End If
        Me.disposedValue = True
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

Public Class TransitionList

    Private mRNG As RNG

    Private mCurrentTrans As Integer
    Private mTransNames As Array = ("BandedSwirl1;BandedSwirl2;BandedSwirl3;Blinds;Blood;CircleReveal1;CircleReveal2;CircleReveal3;CircleStretch;CircularBlur;CloudReveal;Crumble;Disolve;DropFade;Fade;LeastBright;LineReveal1;LineReveal2;LineReveal3;LineReveal4;LineReveal5;LineReveal6;LineReveal7;LineReveal8;MostBright;PixelateIn;PixelateOut;Pixelate;RadialBlur;RadialWiggle;RandomCircle;Ripple;RotateCrumble;Saturate;Shrink;SlideIn1;SlideIn2;SlideIn3;SlideIn4;SmoothSwirlGrid1;SmoothSwirlGrid2;SmoothSwirlGrid3;SmoothSwirlGrid4;SwirlGrid1;SwirlGrid2;Swirl;Water;Wave").Split(";")
    Private mTransList As ArrayList

    Public Sub New()

        mTransList = New ArrayList(mTransNames.GetLength(0))

        For i As Integer = 0 To mTransNames.GetLength(0) - 1
            Select Case mTransNames.GetValue(i).ToString
                Case "BandedSwirl1"
                    mTransList.Add(New TransitionEffects.BandedSwirlTransitionEffect(Math.PI / 5.0, 50.0))
                Case "BandedSwirl2"
                    mTransList.Add(New TransitionEffects.BandedSwirlTransitionEffect(Math.PI, 10.0))
                Case "BandedSwirl3"
                    mTransList.Add(New TransitionEffects.BandedSwirlTransitionEffect(-Math.PI, 10.0))
                Case "Blinds"
                    mTransList.Add(New TransitionEffects.BlindsTransitionEffect())
                Case "Blood"
                    mTransList.Add(New TransitionEffects.BloodTransitionEffect)
                Case "CircleReveal1"
                    Dim t As CircleRevealTransitionEffect = New CircleRevealTransitionEffect
                    t.FuzzyAmount = 0
                    mTransList.Add(t)
                Case "CircleReveal2"
                    Dim t As CircleRevealTransitionEffect = New CircleRevealTransitionEffect
                    t.FuzzyAmount = 0.1
                    mTransList.Add(t)
                Case "CircleReveal3"
                    Dim t As CircleRevealTransitionEffect = New CircleRevealTransitionEffect
                    t.FuzzyAmount = 0.5
                    mTransList.Add(t)
                Case "CircleStretch"
                    mTransList.Add(New TransitionEffects.CircleStretchTransitionEffect)
                Case "CircularBlur"
                    mTransList.Add(New TransitionEffects.CircularBlurTransitionEffect)
                Case "CloudReveal"
                    mTransList.Add(New TransitionEffects.CloudRevealTransitionEffect)
                Case "Crumble"
                    mTransList.Add(New TransitionEffects.CrumbleTransitionEffect)
                Case "Disolve"
                    mTransList.Add(New TransitionEffects.DisolveTransitionEffect)
                Case "DropFade"
                    mTransList.Add(New TransitionEffects.DropFadeTransitionEffect)
                Case "Fade"
                    mTransList.Add(New TransitionEffects.FadeTransitionEffect)
                Case "LeastBright"
                    mTransList.Add(New TransitionEffects.LeastBrightTransitionEffect)
                Case "LineReveal1"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(-0.2, -0.2)
                    t.LineNormal = New System.Windows.Point(1, 0)
                    t.LineOffset = New System.Windows.Point(1.4, 0)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal2"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(1.2, -0.2)
                    t.LineNormal = New System.Windows.Point(-1, 0)
                    t.LineOffset = New System.Windows.Point(-1.4, 0)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal3"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(-0.2, -0.2)
                    t.LineNormal = New System.Windows.Point(0, 1)
                    t.LineOffset = New System.Windows.Point(0, 1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal4"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(-0.2, 1.2)
                    t.LineNormal = New System.Windows.Point(0, -1)
                    t.LineOffset = New System.Windows.Point(0, -1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal5"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(-0.2, -0.2)
                    t.LineNormal = New System.Windows.Point(1, 1)
                    t.LineOffset = New System.Windows.Point(1.4, 1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal6"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(1.2, 1.2)
                    t.LineNormal = New System.Windows.Point(-1, -1)
                    t.LineOffset = New System.Windows.Point(-1.4, -1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal7"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(1.2, -0.2)
                    t.LineNormal = New System.Windows.Point(-1, 1)
                    t.LineOffset = New System.Windows.Point(-1.4, 1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "LineReveal8"
                    Dim t As LineRevealTransitionEffect = New LineRevealTransitionEffect
                    t.LineOrigin = New System.Windows.Point(-0.2, 1.2)
                    t.LineNormal = New System.Windows.Point(1, -1)
                    t.LineOffset = New System.Windows.Point(1.4, -1.4)
                    t.FuzzyAmount = 0.2
                    mTransList.Add(t)
                Case "MostBright"
                    mTransList.Add(New TransitionEffects.MostBrightTransitionEffect)
                Case "PixelateIn"
                    mTransList.Add(New TransitionEffects.PixelateInTransitionEffect)
                Case "PixelateOut"
                    mTransList.Add(New TransitionEffects.PixelateOutTransitionEffect)
                Case "Pixelate"
                    mTransList.Add(New TransitionEffects.PixelateTransitionEffect)
                Case "RadialBlur"
                    mTransList.Add(New TransitionEffects.RadialBlurTransitionEffect)
                Case "RadialWiggle"
                    mTransList.Add(New TransitionEffects.RadialWiggleTransitionEffect)
                Case "RandomCircle"
                    mTransList.Add(New TransitionEffects.RandomCircleRevealTransitionEffect)
                Case "Ripple"
                    mTransList.Add(New TransitionEffects.RippleTransitionEffect)
                Case "RotateCrumble"
                    mTransList.Add(New TransitionEffects.RotateCrumbleTransitionEffect)
                Case "Saturate"
                    mTransList.Add(New TransitionEffects.SaturateTransitionEffect)
                Case "Shrink"
                    mTransList.Add(New TransitionEffects.ShrinkTransitionEffect)
                Case "SlideIn1"
                    Dim t As SlideInTransitionEffect = New SlideInTransitionEffect
                    t.SlideAmount = New System.Windows.Point(1, 0)
                    mTransList.Add(t)
                Case "SlideIn2"
                    Dim t As SlideInTransitionEffect = New SlideInTransitionEffect
                    t.SlideAmount = New System.Windows.Point(0, 1)
                    mTransList.Add(t)
                Case "SlideIn3"
                    Dim t As SlideInTransitionEffect = New SlideInTransitionEffect
                    t.SlideAmount = New System.Windows.Point(-1, 0)
                    mTransList.Add(t)
                Case "SlideIn4"
                    Dim t As SlideInTransitionEffect = New SlideInTransitionEffect
                    t.SlideAmount = New System.Windows.Point(0, -1)
                    mTransList.Add(t)
                Case "SmoothSwirlGrid1"
                    Dim t As SmoothSwirlGridTransitionEffect = New SmoothSwirlGridTransitionEffect
                    t.TwistAmount = Math.PI * 4
                    mTransList.Add(t)
                Case "SmoothSwirlGrid2"
                    Dim t As SmoothSwirlGridTransitionEffect = New SmoothSwirlGridTransitionEffect
                    t.TwistAmount = Math.PI * 16
                    mTransList.Add(t)
                Case "SmoothSwirlGrid3"
                    Dim t As SmoothSwirlGridTransitionEffect = New SmoothSwirlGridTransitionEffect
                    t.TwistAmount = -Math.PI * 8
                    mTransList.Add(t)
                Case "SmoothSwirlGrid4"
                    Dim t As SmoothSwirlGridTransitionEffect = New SmoothSwirlGridTransitionEffect
                    t.TwistAmount = -Math.PI * 6
                    mTransList.Add(t)
                Case "SwirlGrid1"
                    Dim t As SwirlGridTransitionEffect = New SwirlGridTransitionEffect
                    t.TwistAmount = -Math.PI * 4
                    mTransList.Add(t)
                Case "SwirlGrid2"
                    Dim t As SwirlGridTransitionEffect = New SwirlGridTransitionEffect
                    t.TwistAmount = -Math.PI * 16
                    mTransList.Add(t)
                Case "Swirl"
                    Dim t As SwirlTransitionEffect = New SwirlTransitionEffect
                    't.TwistAmount = -Math.PI * 16
                    mTransList.Add(t)
                Case "Water"
                    mTransList.Add(New TransitionEffects.WaterTransitionEffect)
                Case "Wave"
                    mTransList.Add(New TransitionEffects.WaveTransitionEffect)
            End Select
        Next
        mRNG = New RNG

    End Sub

    Public Function GetNextRandom() As TransitionEffect
        Try
            Dim t As Integer = mRNG.GetBall(0, mTransNames.GetLength(0) - 1)
            Return mTransList.Item(t)
        Catch ex As Exception
            Return New TransitionEffects.BlindsTransitionEffect()
        End Try
    End Function



End Class






 

 

Apr 28, 2010 at 4:11 AM
 
I have added another class which instantiates a MediaUriElement in the hope that if I dispose of it then the handles would surely go away .. but alas that was not to be.
These pesky handles just keep grwoing and growing... after 2 hours I have over 100K handles open 
Public Class MEU
    Implements IDisposable

    Private mAssembly As System.Reflection.Assembly
    Private mType As System.Type
    Private mInstance As Object


    Public Sub New()
    End Sub
    Public Function Create() As Boolean
        Try
            Dim AssFile As String = Path.Combine(Path.GetDirectoryName([Assembly].GetEntryAssembly().Location), "WPFMediaKit.dll")
            If File.Exists(AssFile) Then
                mAssembly = System.Reflection.Assembly.LoadFile(AssFile)
                mType = mAssembly.GetType("WPFMediaKit.DirectShow.Controls.MediaUriElement")
                If Not mType Is Nothing Then
                    mInstance = Activator.CreateInstance(mType)
                    Return True
                End If
            End If

        Catch ex As Exception
        End Try
        Return False
    End Function

    Public ReadOnly Property Control() As Object
        Get
            Return mInstance
        End Get
    End Property

#Region " IDisposable Support "

    Private disposedValue As Boolean = False        ' To detect redundant calls
    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                mAssembly = Nothing
                mType = Nothing
                mInstance = Nothing
            End If
            ' TODO: free shared unmanaged resources
        End If
        Me.disposedValue = True
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region


End Class

Apr 28, 2010 at 7:10 PM
I have seen this before and it ended up being some bad directshow filters that were installed on the computer.  Can you test on a clean system and see how it behaves?
Apr 30, 2010 at 1:53 AM

Thanks for the tip!  Looks like it was the onboard chip on the new I3... put in another video card and disabled the onboard and it is working a treat... handles staying around 1600. 

I am however getting a bit of tearing or flickering ... not all the time but random.

Thanks David