Announcement

Collapse
No announcement yet.

Little Help here.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Little Help here.

    DAmn, maybe its late but i'm having a bit of trouble figureing this out.


    I'm actually using frodo's XM satellite .dll and service. There is data that is sent to an event which is sent at different intervals (from the xm device) It's constantly sending data to update new music and new artist. My problem is that the even fires before the code finishes. I know there's a simple resolution here but like I said its late!

    Code:
     Private Sub XM_Control_ChannelData(ByVal Number As Integer, ByVal Station As String, ByVal Artist As String, ByVal Title As String, ByVal Genre As String) Handles XM_Control.ChannelData
    
    'Here's the sub in the class
    
    Public Sub station_update(ByVal station_number As Integer, ByVal station_name As String, ByVal current_artist As String, ByVal current_title As String, ByVal available_genre As String)
    
            Dim newdata As New Threading.Thread(AddressOf update_db_arrayA)
    
            XM_station_number = station_number
            XM_station_name = station_name
            XM_current_artist = current_artist
            XM_current_title = current_title
            XM_available_genre = available_genre
    
            newdata.Start()
    
    
    
    
    
    
        End Sub
    
    
    'Here's the sub the thread is addressed to: 
    
    
    Private Sub update_db_arrayA()
            Dim i As Integer
            Dim buf_station_number As String
            Dim station_updated As Boolean
    
    
    
            '*
            '* Load what we got in the DB into ram
            '*
            System.Windows.Forms.Application.DoEvents()
            If XM_Loaded = False Then
                InitDataBase("sql", "SELECT [File],[File Name],[Genre] FROM MEDIA WHERE Media.[Device]='xm'")
                total_stations = main_recordset.RecordCount
                System.Windows.Forms.Application.DoEvents()
                If Not total_stations = 0 Then
                    For i = 0 To total_stations
                        'File = station number
                        'File name = station name
                        'genre = genre
                        xm_array(0, i) = Convert.ToString(main_recordset(0).Value)
                        xm_array(1, i) = Convert.ToString(main_recordset(1).Value)
                        xm_array(4, i) = Convert.ToString(main_recordset(2).Value)
                        main_recordset.MoveNext()
                    Next
                End If
                Kill_mainConnection()
                XM_Loaded = False
    
    
            End If
    
            i = 0
            If Not total_stations = 0 Then
                For i = 0 To total_stations
                    buf_station_number = xm_array(0, i)
                    If buf_station_number = XM_station_number Then
                        xm_array(0, i) = XM_station_number
                        xm_array(1, i) = XM_station_name
                        xm_array(2, i) = XM_current_artist
                        xm_array(3, i) = XM_current_title
                        xm_array(4, i) = XM_available_genre
                        i = total_stations
                        station_updated = True
                    End If
                Next
            Else
                XM_station_name = XM_station_name.Replace("'", "")
                InitDataBase("sql", "INSERT INTO MEDIA ([File],[File Name],[Genre],[Device]) VALUES ('" & XM_station_number & "','" & XM_station_name & "','" & XM_available_genre & "','xm')")
                Kill_mainConnection()
    
            End If
    
            System.Windows.Forms.Application.DoEvents()
        End Sub
    Progress [I will seriously never be done!]
    Via EPIA MII
    512MB RAM
    OEM GPS (embedded)
    nLite WinXP pro on
    1GB Extreme III CF card
    Carnetix 1260 startup/ DC-DC regulator
    Software: Still, re-Writing my existing front end in .Net

  • #2
    I didn't qutie looked at the code, but as I can understand you are monitoring a folder for new files.
    Use the FileSystemWatcher class in the .NET.
    Very easy and very cool
    My web page
    First I need my own car, then I can start working on a carPC...

    Comment


    • #3
      huh? You didn't quite look at the post either did ya?

      Comment


      • #4
        Probably the DoEvents?
        Destinator 3 For PC! - http://www.map-monkey.co.uk/

        Comment


        • #5
          .

          Tried that. This is the weirdest thing I've ever seen! If I put any other code, for example a timeout for 30 seconds, the code iterates and completes just like normal. As soon as I include database code to run an sql statement within the event it just ignores all the rest of the code and the even is re-fired with another input from the XM service.

          It's not Frodo's service. I'm sure of that...
          Progress [I will seriously never be done!]
          Via EPIA MII
          512MB RAM
          OEM GPS (embedded)
          nLite WinXP pro on
          1GB Extreme III CF card
          Carnetix 1260 startup/ DC-DC regulator
          Software: Still, re-Writing my existing front end in .Net

          Comment


          • #6
            I'm not sure I understand what is going on. Can you explain any better ?
            [H]4 Life
            My next generation Front End is right on schedule.
            It will be done sometime in the next generation.
            I'm a lesbian too.
            I am for hire!

            Comment


            • #7
              have you tried not using a thread in the event handler? just do your DB stuff in the event handler itself?

              also, you're using SqlDataReader? if so, just use the GetString(0), GetString(1), etc. rather than Convert.ToString. if you use the DataReader classes you can simply do

              Code:
              while (reader.Read())
              {
                  string val = reader.GetString(0);
              }
              you shouldn't need DoEvents either. that's a hold over from VB6 days and is typically used in the main GUI thread, not child threads.
              EWF, HORM, MinLogon on XP.

              Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
              Win Embedded Std 2011 RC
              OCZ Vertex Turbo 30GB SSD
              Lilliput 629 Transflective, WRX Screen Mount
              BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
              VoomPC 2

              Comment


              • #8
                .

                Thanks SF for the response. I actually tried your approach first. No doevents, Ran in the original event.

                Instead of a dataset I'm access a record set.

                Abodb.recordset
                Progress [I will seriously never be done!]
                Via EPIA MII
                512MB RAM
                OEM GPS (embedded)
                nLite WinXP pro on
                1GB Extreme III CF card
                Carnetix 1260 startup/ DC-DC regulator
                Software: Still, re-Writing my existing front end in .Net

                Comment


                • #9
                  what happened when you had the DB code in the event handler vs spawned thread? the events should block as each one is handled.

                  also, are you using ADO.NET or ADO? because DataReader and the rest of the ADO.NET classes are more suitable to what you're doing and you'll have less overhead than using COM interop for ADO.
                  EWF, HORM, MinLogon on XP.

                  Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
                  Win Embedded Std 2011 RC
                  OCZ Vertex Turbo 30GB SSD
                  Lilliput 629 Transflective, WRX Screen Mount
                  BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
                  VoomPC 2

                  Comment


                  • #10
                    .

                    Using ADO.net (version 2.8).
                    Progress [I will seriously never be done!]
                    Via EPIA MII
                    512MB RAM
                    OEM GPS (embedded)
                    nLite WinXP pro on
                    1GB Extreme III CF card
                    Carnetix 1260 startup/ DC-DC regulator
                    Software: Still, re-Writing my existing front end in .Net

                    Comment


                    • #11
                      i used a class file that someone here posted, and rather than constantly polling the XM for info, it jus waits til it sends something....i'll post up mine later...

                      Comment


                      • #12
                        Welcome to the joys of real-time programming. I'm not sure but I would guess that there is a non-blocking wait somewhere in the ado connection code (not yours, the database's) so what is happening is the database yields the processor, allowing the main thread to respond to the next event from the XM radio. Because you appear to be using "global" variables to pass the event data, this is getting clobbered and all hell is breaking loose, not the least of which being your thread to write the data to the database being re-started (hence not completing the previous call). I suggest you use a work queue of data to be written and have an always running data write thread. When new data arrives, lock the queue, push the new data on to the queue and unlock it. The db write thread would periodically look at the number of items in the queue and if non-zero, lock the queue, write as many as possible to the database, unlock the queue again and sleep for a while before the next check. The queue locking is important to prevent the two threads trying to write to the queue at the same time..

                        Comment

                        Working...
                        X