Kill a thread after a certain time

I am new programmer with Xojo.
I have a loop that runs sql queries through tasks and I would like to kill the task that takes too long.
I don’t know if this is possible with Xojo and a timer or some other time evaluation ?
I tried something but I think it doesn’t work because the timer seems to be dissociated from the tasks.
Thanks for tips.
Sorry for my english

you could compare two datetimes .SecondsFrom1970 as exit condition.
or using a thread which would not block the ui.
the timer event inside a window occurs only outside of your methods.
in other words a longer running method block the app usage or main thread discontinue.

The database needs to support both cancel and timeout. Or whatever you do won’t matter because even without thread the database continues merrily whatever it did.

Thx for your answer.
So, the solution is not to use a Timer Object and use a Task with Time evaluation.
In the run method of the task, I could have the query select inside a loop with a finish time and a Me.kill ?

Thx for answer :slight_smile:

normal if you do a query you will have this data, so cancel the query seems unusually.
could you limit the amount of returning data?
could you add indices to fields?
if a query hang it could also be a dead lock.

It seems that code below works : it’s the task run method called by a loop through the cursor.

Var d1 As DateTime = DateTime.Now
Var seconds As Double = d1.SecondsFrom1970
Var d2 As New DateTime(seconds + 5, TimeZone.Current)

While d1.SecondsFrom1970 <= d2.SecondsFrom1970
if gTB.Sel = FAIL then
zCurs2 = nil
d1 = DateTime.Now
if d1.SecondsFrom1970 > d2.SecondsFrom1970 then
zCurs2 = nil
zCurs2 = gCurs