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![]()
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
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![]()
huh? You didn't quite look at the post either did ya?![]()
Probably the DoEvents?
Destinator 3 For PC! - http://www.map-monkey.co.uk/
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
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!
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
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.Code:while (reader.Read()) { string val = reader.GetString(0); }
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
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.
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
Bookmarks