(Project included) Strange inconsistent behaviour, enabling MBS timers in array after loading from main code vs a thread

Hello me again… different issue, that I have tried to demonstrate in projects below. Only tested on windows.

TimersInArray_Project1.zip (8.7 KB)

In the project. if I press button A, then C… MBS timers work (only 4 timers, nothing to do with amount of timers)… so far so good.

But if I (clear arrays) and press button B then C the timers don’t enable. The difference being is that A puts the timers in an array in the normal code, and B puts the timers in an array using a thread. The enable script is the same for both (button C). The inspector debugger shows that the timers are loaded into the array in each case.

Why does the enable timer script care how the timers are loaded into the array?
It’s just seems strange? I have a different test project that seems to work, even though there is nothing really different about it. I just cannot get consistent results. The main app I am working on, some timers enable work and some don’t in the enable script (but fine if not loaded into array NOT using a thread), the debugger is showing that it is hitting the enable timer line perfectly, and then showing ‘enable = yes’ in the inspector… but nothing happens (though it does - if loaded not using a thread). Is there something really obvious I am missing here?

Sub Pressed() Handles Pressed
  // Create and start the TimerSetupThread
  ClearArrays
  'TextArea1.AddText("Loading timers into Array using thread..." +endofline)
  Dim setupThread As New TimerSetupThread
  setupThread.Run
End Sub

You instantiate the thread, execute it and then the object is killed directly.
Add the variable as property Window1 and then instantiate it there.

1 Like

Many thanks for your reply Marius, I appreciate it.
I tired adding property

Public Property setupThread As TimerSetupThread

on to window1, and changed the button code to.

Sub Pressed() Handles Pressed
  // Create and start the TimerSetupThread
  ClearArrays
  'TextArea1.AddText("Loading timers into Array using thread..." +endofline)
  
  setupThread = new TimerSetupThread
  setupThread.Run
End Sub

But it’s still the same (doesn’t fire timers).
Was that the correct thing to do? Quite willing to think I am being stupid here :joy:

project:
TimersInArray_Project2.zip (8.7 KB)

For me, they all fire.

Thanks Marius it doesn’t seems to work for me, is it possible to tell me if you are on macOs or windows? I’m wondering if it’s OS specific? Though I can’t seem to pin down the problem at all.

Downloaded your project, it works with macOS 13.6.7.
Clicking B then C:
image

Ok, I just tested with the MBS-Timer Exampleproject.
When the MBSTimer ist created from within a Thread ON WINDOWS, it doesn’t fire.
On Mac both work, on Windows only the Xojo Timer does.
Perhaps @Christian_Schmitz could help here.

Here is the project: https://nözl.de/28a1b

Well, the messaging in Windows won’t work if you create it on a thread as the Xojo thread would own the timer and thus never process any messages like the main thread does.

Please create TimerMBS only on the main thread on Windows.

2 Likes