59997 - BackgroundTasks not reentrant?

This is a bug, which could happen in every Xojo app and may even do so with built-in plugins.

The problem is that you may call a method, which yields CPU time to other threads in the Xojo app.
This may run a timer, which itself runs another plugin method, which yields. And that causes a crash.

In my opinion this one should get some attention as it affects all targets.

Hi Christian

Do you think this could be same issue I was discussing with you recently when yielding could cause a crash or the code to stop running?

Maybe. It can crash any bigger app anytime when yielding.

And a BackgroundTasks False pragma would not help?
(in case of a crash, that is. Not in terms of freeing the CPU obviously …)

Has a bug report been filed?

It’s in the subject line: feedback://showreport?report_id=59997

2 Likes

We would like to be able to yield, even if we yield in yield.

What is a “background task” in this context? I’m only aware of threads, one of which is the main thread.

The crash report is from me. I have a very simple SQLite database. I wanted to use the multithread versions of the MBS plugin to avoid showing the beachball. There is a lot of data that is written to the database. Write a couple of thousand times and get a nice crash. Because of the bug I have to open an close the database for each write operation.

Calling code:

call ConnectToDatabaseLocalMBS
if not ConnectedToSQLite then Return
WriteLocalMBS(theRecID, MessageBody)
CloseSQLite

Writing to the database:

dim thePreparedStatement as SQLPreparedStatementMBS = SQLiteIndexDBMBS.Prepare("INSERT INTO bodyindex(docid, messagebody) VALUES(" + str(theRecID) + ", ?)")
thePreparedStatement.BindType(0, thePreparedStatement.kTypeString)
thePreparedStatement.SQLExecuteMT(MessageBody)

SQLiteIndexDBMBS.CommitTransaction
thePreparedStatement = Nil