Hi,
I have the following query which I am executing as part of a non-ui service:
The problem I have is the code does not appear to "Wait For" the query to be complete before continuing on with the rest of the code.
The main program is:
I wish to use the async query to make the program responsive to network requests.
Am I doing something wrong and do I need to create a separate thread for the network interface and use non async queries?
I noticed that the sleep(10000) statement in the simple example program below doesn't provide a ten second delay.
Best regards
Rob
I have the following query which I am executing as part of a non-ui service:
Asynch Insert Query using Wait For:
private Sub insertRecsToTempBuffer(recList As List, tblTempMetaDataArg As tblTemp_Meta_t, N5Arg As Int)
Dim n As Int = 1
Dim listN As Int
listN = recList.Size
Dim qryStr As String
qryStr = _
$"INSERT INTO tblAgg2SecTemp(
julianDateUTC, ...
... JdateTime5MinStr)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"$
sqlDbAggTemp.BeginTransaction
'Set up the arguments - values to be inserted
For Each row() As String In recList
Dim ArgArray As List
ArgArray.Initialize
ArgArray.Add(row(0))...
...
'If we are at the last records then add in the data time - don't do this for all the query is slow
If n = listN Then
'Add the time to the last record
ArgArray.Add(DateTime.Now) '13
Else
ArgArray.Add(0) '13
End If
ArgArray.Add(N5Arg) '14
ArgArray.Add(DateTime.Date(row(3)) & " " & DateTime.Time(row(3))) '15
ArgArray.Add(jdt.jdDateTimeToDateTimeStr(row(2))) '16
'Insert transaction
Try
sqlDbAggTemp.AddNonQueryToBatch(qryStr, ArgArray)
n = n + 1
Catch
closeAllDataBases
Dim LogMsgStr As String = "Insert records into AggTemp query failed"
setErrRecAndSave(8, listN, -1, LogMsgStr, LastException, True)
End Try
Next
'Execute batch insert query
Dim SenderFilter As Object = sqlDbAggTemp.ExecNonQueryBatch("sql")
Wait For (SenderFilter) sql_NonQueryComplete (Success As Boolean)
The problem I have is the code does not appear to "Wait For" the query to be complete before continuing on with the rest of the code.
The main program is:
Main Program:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#AdditionalJar: sqlite-jdbc-3.32.3.2
#End Region
'============================================================================================
Sub Process_Globals
Private ipc As ipcComms
Private dbf As dbFcn
Private dProc As dataProcControl
End Sub
'============================================================================================
Sub AppStart (Args() As String)
jdt.initDateTimeConversions("-", ":")
' ipc.Initialize
If dbf.Initialize = False Then
'Handle error TODO
End If
If dProc.Initialize(dbf) = False Then
'Handle error TODO
End If
StartMessageLoop
End Sub
'============================================================================================
Sub doAgg As Boolean
dbf.doAggregate 'This calls the query function '
End Sub
I wish to use the async query to make the program responsive to network requests.
Am I doing something wrong and do I need to create a separate thread for the network interface and use non async queries?
I noticed that the sleep(10000) statement in the simple example program below doesn't provide a ten second delay.
Sleep In a Non-Ui Example:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
Log("Start")
Log("BeforeWrapper")
wrapper
Log("AfterWrapper")
StartMessageLoop
End Sub
Sub wrapper
Log("Before Sum")
Sum(10, 20)
Log("After Sum")
End Sub
Sub Sum(x As Int, y As Int)
Log(x)
Sleep(10000)
Log("Sum = " & (x + y))
End Sub
Best regards
Rob