Threading and DirectX problem.

stelmate

New member
Joined
May 26, 2007
Messages
3
Programming Experience
1-3
I'm having slight threading problems. I'm using the following code to invoke a thread with a Microsoft.DirectX.AudioVideoPlayback.Video instance running on a panel in the background.

VB.NET:
    Private Sub Play(ByVal filename As String)
        If Vid Is Nothing Then
            Vid = New Video(filename, True)
            Vid.Owner = movieScreen
            Vid.Caption = filename
            Vid.Size = New Size(movieScreen.Width, movieScreen.Height)
            Dim Timerstamp As New Timerstamp(Vid, videoLabel)
            Dim timerThread As New Thread(AddressOf Timerstamp.LabelUpdater)
            timerThread.IsBackground = True
            timerThread.Priority = ThreadPriority.Lowest
            timerThread.Start()

Then my Timerstamp object simply does the following (updates a label)

VB.NET:
    Public Sub LabelUpdater()
        Dim method As New MethodInvoker(AddressOf UpdatelLabel)
        statusLabel.Invoke(method)
    End Sub

    Private Sub UpdatelLabel()
        If Not video Is Nothing Then
            Dim filename = video.Caption
            Dim mins As Integer
            Dim secs As Integer
            Dim totalmins, totalsec As Integer
            totalsec = video.Duration
            totalmins = totalsec / 60
            totalsec = totalsec Mod 60
            While video.Playing And video.Caption = filename And (video.CurrentPosition < video.Duration)
                secs = video.CurrentPosition Mod 60
                mins = video.CurrentPosition / 60

                statusLabel.Text = "Current: " & mins & ":" & secs & vbNewLine & "Total: " & totalmins & ":" & totalsec
                statusLabel.Refresh()
                Thread.Sleep(TimeSpan.FromSeconds(10))

            End While
        End If
    End Sub

However, when I run this, the instance of the Video that I'm running in the background appears to lose focus on its Panel (it stays centered in the screen even when you move the form around) and the program locks up.

Any help would be much appreciated.
 
Back
Top