# Thread acting as a timer issue

**URL:** <https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926>\
**Category:** General\
**Created:** [September 23, 2026, 11:10pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926 "2026-09-23T23:10:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 23, 2026, 11:10pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/1 "2026-09-23T23:10:43Z")

</div>

Hi folks.

I have run into an issue that is making me frustrated.

I’m running Xojo 2025R2 on mac Sonoma.

I have a thread that will update on a window a label, so people can see the program is running, even if it isn’t showing anything.

here is the code for threadForRunningTime.Run

```auto
static runTimerValue As Integer

While app.runningTime = TRUE

runTimerValue = runTimerValue + 1

Me.AddUserInterfaceUpdate("timeCounter":runTimerValue)

Thread.SleepCurrent(1000)

Wend

```

And in my threadForRunningTime.UserInterfaceUpdate:

```auto
Var seconds As Integer

If data.LastIndex >= 0 Then

Var arg As Dictionary = data(data.LastIndex)

If arg.HasKey("timeCounter") Then
seconds = arg.Value("timeCounter").IntegerValue
labelProgramRunTime.Text = seconds.ToString
End If

End If

```

The issue I have is that instead of getting 1..2..3.. it screams up to tens of thousands. And just stops.

Or locks up my program and xojo.

If I remove the Me.AddUserInterface… it seems to act normally according to my log file.

`7:12:19 PM : There are 45 total rows`  
`7:12:21 PM : ********MATCH FOUND******** `  
`: I = 4 J = 6`  
`: ********MATCH FOUND******** `  
`: I = 4 J = 18`  
`: ********MATCH FOUND******** `  
`: I = 4 J = 20`  
`7:12:22 PM : ********MATCH FOUND******** `  
`: I = 6 J = 18`  
`: ********MATCH FOUND******** `  
`: I = 6 J = 20`  
`7:12:23 PM : ********MATCH FOUND******** `  
`: I = 9 J = 16`  
`: ********MATCH FOUND******** `  
`: I = 9 J = 19`  
`: ********MATCH FOUND******** `  
`: I = 9 J = 23`  
`7:12:24 PM : ********MATCH FOUND******** `  
`: I = 11 J = 12`  
`7:12:25 PM : ********MATCH FOUND******** `  
`: I = 13 J = 37`  
`: ********MATCH FOUND******** `  
`: I = 14 J = 22`  
`7:12:26 PM : ********MATCH FOUND******** `  
`: I = 15 J = 43`  
`: ********MATCH FOUND******** `  
`: I = 16 J = 19`  
`: ********MATCH FOUND******** `  
`: I = 16 J = 23`  
`: ********MATCH FOUND******** `  
`: I = 17 J = 21`  
`: ********MATCH FOUND******** `  
`: I = 18 J = 20`  
`7:12:27 PM : ********MATCH FOUND******** `  
`: I = 19 J = 23`  
`7:12:28 PM : ********MATCH FOUND******** `  
`: I = 24 J = 31`  
`7:12:29 PM : ********MATCH FOUND******** `  
`: I = 26 J = 27`  
`: ********MATCH FOUND******** `  
`: I = 28 J = 33`  
`7:12:32 PM : Done and Dusted`  
`: ABOUT TO STOP RUNNING TIME`  
`: RUNNING TIME IS NOW: False`  
`7:1`

Any ideas?

Regards

---

<div class="post-metadata">

**Author:** ![Clifford\_Antrim](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_antrim/32/507_2.png) [@Clifford\_Antrim](https://forum.xojo.com/u/Clifford_Antrim)\
**Post date:** [September 24, 2026, 12:00am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/2 "2026-09-24T00:00:23Z")

</div>

If the thread isn’t doing anything other than acting as a timer, just use a timer.

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 12:31am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/3 "2026-09-24T00:31:25Z")

</div>

Hi Clifford.

Thank you for the response.

The reason I am using a thread as a timer is I have the program doing processor heavy work. If I try to do it with a timer, my program doesn’t update until after the work has been completed.

Regards

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [September 24, 2026, 3:00am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/4 "2026-09-24T03:00:04Z")

</div>

> [@Michael\_Cebasek](#):
>
> `Me.AddUserInterfaceUpdate`

`AddUserInterfaceUpdate` uses a Timer internally.

> [@Michael\_Cebasek](#):
>
> If I try to do it with a timer, my program doesn’t update until after the work has been completed.

Have you tried using `Thread.YieldToNext()` instead of `Thead.SleepCurrent(1000)`?

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [September 24, 2026, 4:06am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/5 "2026-09-24T04:06:00Z")

</div>

Are you using preemptive threads?

---

<div class="post-metadata">

**Author:** ![Jerry\_Fritschle](https://forum.xojo.com/user_avatar/forum.xojo.com/jerry_fritschle/32/223_2.png) [@Jerry\_Fritschle](https://forum.xojo.com/u/Jerry_Fritschle)\
**Post date:** [September 24, 2026, 4:32am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/6 "2026-09-24T04:32:05Z")

</div>

> [@Michael\_Cebasek](#):
>
> The reason I am using a thread as a timer is I have the program doing processor heavy work.

So is the “processor heavy work” going on in the main thread? This sounds backwards to me.

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 10:47am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/7 "2026-09-24T10:47:44Z")

</div>

Thanks Andrew.

I’m getting so many good hints.

Thank you.

I will try and advise.

Regards

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 10:48am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/8 "2026-09-24T10:48:32Z")

</div>

Yes, Eric.

Thanks for the response.

Regards

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [September 24, 2026, 10:58am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/9 "2026-09-24T10:58:15Z")

</div>

> [@Michael\_Cebasek](#):
>
> `static runTimerValue As Integer`

why its not  
` var runTimerValue as integer = 0`

i made a test and it ticks every second and update the UI, but i not waited until 10000 secods.  
i chaged the sleep to few ms and it count to 10000.

if ui not get updates maybe a other running method blocks the main event loop.

in the `UserInterfaceUpdate` you could output if the event comes in  
by look at the messages window in the IDE.

```auto
Var d As DateTime = DateTime.Now
System.DebugLog CurrentMethodName + " " + d.ToString

```

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 11:02am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/10 "2026-09-24T11:02:43Z")

</div>

Thanks Marcus.

I’ll try this.

I set the runtimerValue to static so that it wouldn’t revert to 0 at every run.

Can you show me what you attempted (ie post your project) so I can look at it?

If not, it is totally fine.

Have a great day.

Regards

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [September 24, 2026, 12:49pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/11 "2026-09-24T12:49:16Z")

</div>

First thing I would try is `Me.Sleep(1000)` instead of `Thread.SleepCurrent(1000)` since you have a reference to the thread instance. There is no good reason to call the shared method version in this case.

But I agree with the others, your approach sounds backwards. Threads should be used for the heavy work so the main thread can keep the UI responsive. Doing the heavy work in the main thread and trying to use a thread as a timer isn’t really going to work since you still need the main thread to actually show the progress.

That’s where I would start my refactoring. I do not recommend preemptive threads, at least not at this stage. They’re a fantastic way to shave a few years off your life expectancy due to stress. Cooperative threads will take you a long way in most workloads. And if not, come on back and we’ll help you with workers and/or preemptive threads.

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 4:52pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/12 "2026-09-24T16:52:21Z")

</div>

Thank you for the response, Thom.

A question however. How do i set the priority of the main thread.

When I create the other threads, I can set their priority. And set them as pre-emptive or cooperative.

Now a quick update (?)

I created a very simple project 1 button, 1 label, 1 thread, 1 timer and it works perfectly with this code:

In the button.Press

```auto
app.runningTime = TRUE

Window1.Thread1.Start

System.DebugLog "Button pressed"

// for testing only
System.DebugLog "The thread has been started"

```

In the thread.run

```auto
static runTimerValue as Integer

while app.runningTime = TRUE

runTimerValue = runTimerValue + 1

Me.AddUserInterfaceUpdate("timeCounter":runTimerValue)

Thread.SleepCurrent(1000)

wend

```

In the thread.UserInterfaceUpdate:

```auto
Var seconds As Integer

For Each arg As Dictionary In data

If arg.HasKey("timeCounter") Then
seconds = arg.Value("timeCounter")
Label1.Text = seconds.ToString
End If

next

```

In my timer.run

Thread1.Resume

And it works perfectly.

As a note / notes:

I have to use a static variable in thread.run, or the value of the variable resets every time the thread runs.

And the reason I use the threads is because BEFORE I did this in my real program, the UI for the progam did indeed become unresponsive (or gave the illusion). The program ran, finished cleanly, but I hated the fact that I couldn’t do anything with the window.

Regards

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [September 24, 2026, 5:31pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/13 "2026-09-24T17:31:33Z")

</div>

explained when the ui updates do his job (without a thread)  
means if you are inside of a method the ui update do not work,  
it will called after your method is finished  
this main event loop is hidden and handled by xojo framework.  
Anyway, I can explain the process and the behavior to myself.

```auto
do
 ui update
 dosomething
loop

function dosomething
 do something longer
end function

```

with a thread it is different  
in its run event it can do something as long as you want because its interrupted by the xojo framework to do something else and update the UI, and later the thread continue.  
that is the reason you put this dosomething longer method in a thread and start it there.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [September 24, 2026, 5:51pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/14 "2026-09-24T17:51:44Z")

</div>

The main thread is locked to priority 5. What is your worker thread doing? Cooperative threads yield at loop boundaries, so if you’re making a plugin or other call that does not itself yield, a separate thread will not help.

Your code sounds more complicated than it needs to be though. On your window you should have a button, a timer, a thread, and a property. The button will start the timer, thread, and clear the counter. The thread does its work. The property stores the counter. The timer increments the counter and updates the label. Use a UserInterfaceUpdate at the end of the thread to signal when the work is complete so you can update the UI accordingly, such as stopping the timer. That’s really all there is to it. If your UI locks up when built this way, it means your work thread isn’t yielding any time to other threads. That’s the true problem that needs to be solved.

Without knowing what the work thread is doing, it’s impossible to suggest a solution. It could need some explicit yield or sleep statements, it could need to be a worker, or maybe even a preemptive thread.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [September 24, 2026, 8:41pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/15 "2026-09-24T20:41:50Z")

</div>

This sounds like a bug I saw in 2024R3.1, I thought they had fixed it by 2025R2 but maybe not?  
[https://tracker.xojo.com/xojoinc/xojo/-/work\_items/77567](https://tracker.xojo.com/xojoinc/xojo/-/work_items/77567)

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [September 24, 2026, 11:59pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/16 "2026-09-24T23:59:32Z")

</div>

Thanks to everyone who helped. I found the problem, though I have NO idea why this worked.

In my threadForRunningTimer, all I had to do was change Pre-emptive to Collaborative.

If anyone can explain why that worked (and I know in one of the many test iteratives of the program I created I did do that) I’m willing to be educated.

Once again thanks to everyone who helped.

Regards

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [September 25, 2026, 5:42am UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/17 "2026-09-25T05:42:04Z")

</div>

I still hope you’ve not disregarded the advice you got in this thread. Your main thread should do the minimal work and a secondary thread should be where most of the work is done.  
I have the impression you have tried to solve your problem while continuing in the same wrong way, and that’s not going to work in the end. Always better to refactor earlier rather than when all seems done and you’re finally forced to refactor way more than you could have done.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [September 25, 2026, 2:00pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/18 "2026-09-25T14:00:07Z")

</div>

> [@Michael\_Cebasek](#):
>
> If anyone can explain why that worked (and I know in one of the many test iteratives of the program I created I did do that) I’m willing to be educate

This is confusing, because what you report sounds exactly like this bug: [https://tracker.xojo.com/xojoinc/xojo/-/work\_items/77567](https://tracker.xojo.com/xojoinc/xojo/-/work_items/77567)  
But that should have been fixed before version 2025R2.

Are you 100% sure you are using 2025R2 ? Perhaps you found another way to trigger the bug?

---

<div class="post-metadata">

**Author:** ![Jerry\_Fritschle](https://forum.xojo.com/user_avatar/forum.xojo.com/jerry_fritschle/32/223_2.png) [@Jerry\_Fritschle](https://forum.xojo.com/u/Jerry_Fritschle)\
**Post date:** [September 25, 2026, 11:06pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/19 "2026-09-25T23:06:31Z")

</div>

> [@Michael\_Cebasek](#):
>
> In my threadForRunningTimer, all I had to do was change Pre-emptive to Collaborative.

This is because a cooperative thread yields to other threads (including the main one) when it can, like between iterations of a loop. I wonder, though, whether you saw the difference when debugging in the IDE; last I knew, all threads are cooperative in the IDE, and you only see the difference in a built app.

Respectfully, though, per my earlier comment and in agreement with Arnaud, it sure sounds like your approach is backwards, and will give you maintenance problems in the future.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [September 25, 2026, 11:30pm UTC](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926/20 "2026-09-25T23:30:15Z")

</div>

> [@Jerry\_Fritschle](#):
>
> debugging in the IDE; last I knew, all threads are cooperative in the IDE, and you only see the difference in a built app.

That is not true.

[Next page](https://forum.xojo.com/t/thread-acting-as-a-timer-issue/88926.md?page=2)
