Hi everyone, I’m (re)trying to use Preemptive Threads (for the second time) for bulk data insertion into a MySQL database. I’d already tried using them in the past with xojo 2025 and the Xojo plugin for MySQL, but the problem seemed to be the plugin itself, which wasn’t compatible with Preemptive Threads. I’d continued to use Cooperative Threads, which didn’t seem to have any problems but did crash the GUI.
Now I’m trying to use the MBS plugin, but I’m still having problems.
The application terminates on its own without reporting errors, even in debug. Or rather, the threads run for a while (about 2000 inserts), and then debugging closes the application without even reporting errors.
I created a thread that, in his run code:
- Opens the connection to the database then inserts one record
I instantiate four threads of this type (my PC has 8 cores), then I activate a timer that cycles through the instantiated threads every second and launches the threads that are not running.
this is the run code of thread :
Dim dbTH As New SQLDatabaseMBS
Dim sq As String
dim i as Integer
dbTH.DatabaseName="mysql:127.0.0.1,3306@attivita"
dbTH.UserName="usertest"
dbTH.Password="pswtest"
Dim f As FolderItem= New FolderItem("C:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.dll")
Call SQLGlobalsMBS.SetDllDirectory("C:\Program Files\MySQL\MySQL Server 5.7\lib")
dbTH.Option("CLIENT_MULTI_STATEMENTS") = "true"
dbTH.Option("CLIENT_MULTI_RESULTS") = "true"
dbTH.Option("AutoCache") = "true"
dbTH.SetFileOption SQLConnectionMBS.kOptionLibraryMySQL, f
Try
dbTH.Connect
Catch err As RuntimeException
Exit Sub
End Try
sq="insert into allegati (idAttivitaSecondaria, datainserimento) values( " +Str(Me.ThreadID+i)+", now() ) "
Try
dbTH.ExecuteSQL(sq)
Catch err As RuntimeException
Exit Sub
End Try
this is the code inside the timer : (thar run each second )
Dim i As Integer
For i=0 To arrayTHREAD.Count-1 '..in this array there are the 4 instanced thread
If arrayTHREAD(i).ThreadState=Thread.ThreadStates.NotRunning Then
Try
arrayTHREAD(i).Start
Catch err As RuntimeException
End Try
End If
Next i
after about 2000 inserts, the IDE/debug closed the application without generating any errors, but if i check the windows log events i found these kind of errors
Does anyone have any code examples showing how to use preemptive threads to continuously insert data into a database, or an explanation for these types of errors?

