Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a program that receives (UDP) data then plays the correct audio file. I have added a timer that will ignore the incoming data and loop audio in a player. I am current ly doing this with a timer set at 500 milliseconds.

 

   Private Sub tmrTimedEvents_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmrTimedEvents.Elapsed
       Dim dTmp As Date
       Dim lTime As Long
       Dim lhour As Long, lminute As Long, lsecond As Long
       Dim CurrentDayStr = Format(System.DateTime.FromOADate(Today.ToOADate), "dddd")
       On Error Resume Next

       If Trim$(strTimeEvent(SE)) <> "" Then
           dTmp = CDate(strTimeEvent(SE))
           If Format(Now, "hh:mm:ss tt") = Format(dTmp, "hh:mm:ss tt") And CurrentDayStr = EventDay Then
               If SE = 0 Then 'SE = 0 is start time, 1 is end time
                   SE = 1
                   BlackOut(True, False, "")
                   blnRuning = True
               Else
                   SE = 0
                   'AdvanceTimedList()
                   'RunTimedEvent()
                   BlackOut(False, False, "")
                   blnRuning = False
               End If
           End If
       End If
   End Sub

 

   Public Sub BlackOut(ByVal blnEnable As Boolean, ByVal blnOnFly As Boolean, ByVal strBeginEnd As String)
       Dim TimeListDay As ListView.SelectedListViewItemCollection = MainForm.lvTimedEvents.SelectedItems
       Dim SelectedTime As ListViewItem
       For Each SelectedTime In TimeListDay
           If blnOnFly = False Then
               If blnEnable = True Then
                   If SwitcherChanged = 0 Then
                       If MediaPlayers(7).FileName = "" Then
                           Exit Sub
                       Else
                           ChangeSwitcher()
                           MediaPlayers(7).Play()
                           SpotPlaying = 7
                           MainForm.lblNextEvent.Text = " Next Event - " & strTimeEvent(SE) & " Stop - " & SelectedTime.SubItems(3).Text
                       End If
                   Else
                       SpotPlaying = 7
                   End If
               Else
                   NextInList()
                   If MainForm.lvTimedEvents.Items(0).Index = MainForm.lvTimedEvents.Items.Count Then
                       MainForm.lvTimedEvents.Items.Clear()
                       Exit Sub
                   End If
               End If
           ElseIf blnOnFly = True Then
               If UCase(strBeginEnd) = "START" Then
                   blnRuning = True
                   SE = 1
                   If SwitcherChanged = 0 Then
                       If MediaPlayers(7).FileName = "" Then
                           Exit Sub
                       Else
                           ChangeSwitcher()
                           MediaPlayers(7).Play()
                           SpotPlaying = 7
                           'MainForm.lblNextEvent.Text = " Next Event - " & strTimeEvent(SE) & " Stop - " & SelectedTime.SubItems(3).Text
                       End If
                   Else
                       SpotPlaying = 7
                   End If
               ElseIf UCase(strBeginEnd) = "STOP" Then
                   OnFlyThread = New Thread(AddressOf modThreadCalls.OnflyThreading)
                   OnFlyThread.Start()
               End If
           End If
       Next
   End Sub

 

I have had an issue arise twice so far where for some reason the ending event is missed and the timer the looping audio doesn't stop.

 

The only thing I can think of is that the system was "responding slow" and when the timer ran the endtime had passed. Any Ideas of what I might be able to do to make sure this doesn't happen. As of right now the timer runs in the main thread. I thought about running it in a seperate thread to see what happens.

 

Thanks for any help you may be

 

Paul

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted

If you reallly want to use this line: on error resume next

At least do something like System.Diagnostics.Debug.Assert(err.number == 0) (I dont know if err.number still works, but it did in vb6 ;) ).

 

The Assert method is only performed in a debug build and what it does is check if the condition is true, if not (in this case if there is an error) it will generate a popup. That way you know when an error occurred -> meaning you have some problem to debug ;).

 

It would be even better if you started to use the new try..catch... construction ;).

 

 

I'm not sure the timer events are raised on the main thread. Try checkin this with MainForm.lvTimedEvents.InvokeRequired. If that returns true, you're not on the main thread and your life just became a lot more complicated ;).

Nothing is as illusive as 'the last bug'.
Posted

Thanks, I'll try that to see if any thing is raised/caught. I'll post my results. Now I am moving the program to a computer that has less of a work load. but either way I'll post.

 

Thasnk for your help.

 

Paul

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

  • 4 weeks later...
Posted

Well it took awhile but I added the "try, catch, end try" and well some events were missed and no event was raised. I got the app moved to the new computer and all seems well.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...