Discussion:
Timer issue?
Jean-Luc Arnaud
2018-08-01 10:43:21 UTC
Permalink
Hi all,

I'm using a timer in order to terminate a thread treatment:

- When finished, the thread sets a flag to True and terminates (verified),

- In the Timer (with a period of 10), when the flag is on, the timer
sets itself to off and then calls a method selecting the next file to be
treated.

Globally, this works but sometimes, I'm getting a "File already opened"
error that I send when this method tries to open the same file that is
already opened. This should never happen !!! It's like the method is
called again whereas it has already opened a new file and tries to
reopen it ! I have verified that this is always a new file, never the
last treated file.

Here is what I'm getting raising a Runtime error when this happens:

RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent)
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main

Can you help me understand what's happening ?

TIA
--
Jean-Luc Arnaud
Jon Ogden
2018-08-01 11:59:15 UTC
Permalink
What version Xojo? What OS? 64 bit?

Sent from my iPhone
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer sets itself to off and then calls a method selecting the next file to be treated.
Globally, this works but sometimes, I'm getting a "File already opened" error that I send when this method tries to open the same file that is already opened. This should never happen !!! It's like the method is called again whereas it has already opened a new file and tries to reopen it ! I have verified that this is always a new file, never the last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Jean-Luc Arnaud
2018-08-01 12:18:02 UTC
Permalink
Xojo 2018r1.1, OS X 10.13.6, 64bit.

Sorry for forgetting this information.

Jean-Luc Arnaud
Post by Jon Ogden
What version Xojo? What OS? 64 bit?
Sent from my iPhone
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer sets itself to off and then calls a method selecting the next file to be treated.
Globally, this works but sometimes, I'm getting a "File already opened" error that I send when this method tries to open the same file that is already opened. This should never happen !!! It's like the method is called again whereas it has already opened a new file and tries to reopen it ! I have verified that this is always a new file, never the last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Jon Ogden
2018-08-01 12:56:18 UTC
Permalink
Try a Xojo 2017 version and see if the same problem happens. Just a guess.

Sent from my iPhone
Post by Jean-Luc Arnaud
Xojo 2018r1.1, OS X 10.13.6, 64bit.
Sorry for forgetting this information.
Jean-Luc Arnaud
Post by Jon Ogden
What version Xojo? What OS? 64 bit?
Sent from my iPhone
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer sets itself to off and then calls a method selecting the next file to be treated.
Globally, this works but sometimes, I'm getting a "File already opened" error that I send when this method tries to open the same file that is already opened. This should never happen !!! It's like the method is called again whereas it has already opened a new file and tries to reopen it ! I have verified that this is always a new file, never the last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
g***@bitbazar.com
2018-08-01 12:06:52 UTC
Permalink
Hi Jean-Luc,

did you try to set the timer period to a considerably longer interval?

just to understand if in the 10 milliseconds (that’s really a short interval maybe also for a computer), the timer event is fired again before completing its tasks, including set itself to off


you could try maybe a quarter of second, that anyway is nothing if you are handling a series of files sequentially

just a guess,

 Giulio

Giulio Mastrosanti
BitBazar srl
06 39737052 / 06 39725787
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer
sets itself to off and then calls a method selecting the next file to be
treated.
Globally, this works but sometimes, I'm getting a "File already opened"
error that I send when this method tries to open the same file that is
already opened. This should never happen !!! It's like the method is
called again whereas it has already opened a new file and tries to
reopen it ! I have verified that this is always a new file, never the
last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent)
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Jean-Luc Arnaud
2018-08-01 12:20:21 UTC
Permalink
Thanks for the idea, Giulio.

Actually, the same timer is used in refreshing the UI interface. But I
will try what you're suggesting and let you know.

Jean-Luc Arnaud
Post by g***@bitbazar.com
Hi Jean-Luc,
did you try to set the timer period to a considerably longer interval?
just to understand if in the 10 milliseconds (that’s really a short
interval maybe also for a computer), the timer event is fired again
before completing its tasks, including set itself to off

you could try maybe a quarter of second, that anyway is nothing if you
are handling a series of files sequentially
just a guess,
 Giulio
Giulio Mastrosanti
*BitBazar srl*
06 39737052 / 06 39725787
Il 1 ago 2018, 12:43 +0200, Jean-Luc Arnaud
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer
sets itself to off and then calls a method selecting the next file to be
treated.
Globally, this works but sometimes, I'm getting a "File already opened"
error that I send when this method tries to open the same file that is
already opened. This should never happen !!! It's like the method is
called again whereas it has already opened a new file and tries to
reopen it ! I have verified that this is always a new file, never the
last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent)
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Tim Jones
2018-08-01 18:45:15 UTC
Permalink
HI Jean-Luc,

I'd recommend that you use 2 timers with what you're doing. One to handle the UI updates and the second for your thread manager.

--
Tim
Post by Jean-Luc Arnaud
Thanks for the idea, Giulio.
Actually, the same timer is used in refreshing the UI interface. But I will try what you're suggesting and let you know.
Jean-Luc Arnaud
Post by g***@bitbazar.com
Hi Jean-Luc,
did you try to set the timer period to a considerably longer interval?
just to understand if in the 10 milliseconds (that’s really a short interval maybe also for a computer), the timer event is fired again before completing its tasks, including set itself to off

you could try maybe a quarter of second, that anyway is nothing if you are handling a series of files sequentially
just a guess,
 Giulio
Giulio Mastrosanti
BitBazar srl
06 39737052 / 06 39725787
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer
sets itself to off and then calls a method selecting the next file to be
treated.
Globally, this works but sometimes, I'm getting a "File already opened"
error that I send when this method tries to open the same file that is
already opened. This should never happen !!! It's like the method is
called again whereas it has already opened a new file and tries to
reopen it ! I have verified that this is always a new file, never the
last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent)
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Jean-Luc Arnaud
2018-08-02 07:57:31 UTC
Permalink
Many thanks to Tim, Jon and Giulio for their replies and their help.

Increasing the period to 350 ms seems to be a solution, without effect
on UI refresh.

In addition, I think Tim's suggestion is a very good one, and I will
apply it. One of the benefits is to set two different periods for UI
refresh and end task management.

Thank you very much.

Jean-Luc Arnaud
Post by Tim Jones
HI Jean-Luc,
I'd recommend that you use 2 timers with what you're doing.  One to
handle the UI updates and the second for your thread manager.
--
Tim
Post by Jean-Luc Arnaud
Thanks for the idea, Giulio.
Actually, the same timer is used in refreshing the UI interface. But
I will try what you're suggesting and let you know.
Jean-Luc Arnaud
Post by g***@bitbazar.com
Hi Jean-Luc,
did you try to set the timer period to a considerably longer interval?
just to understand if in the 10 milliseconds (that’s really a short
interval maybe also for a computer), the timer event is fired again
before completing its tasks, including set itself to off

you could try maybe a quarter of second, that anyway is nothing if
you are handling a series of files sequentially
just a guess,
 Giulio
Giulio Mastrosanti
*BitBazar srl*
06 39737052 / 06 39725787
Il 1 ago 2018, 12:43 +0200, Jean-Luc Arnaud
Post by Jean-Luc Arnaud
Hi all,
- When finished, the thread sets a flag to True and terminates (verified),
- In the Timer (with a period of 10), when the flag is on, the timer
sets itself to off and then calls a method selecting the next file to be
treated.
Globally, this works but sometimes, I'm getting a "File already opened"
error that I send when this method tries to open the same file that is
already opened. This should never happen !!! It's like the method is
called again whereas it has already opened a new file and tries to
reopen it ! I have verified that this is always a new file, never the
last treated file.
RuntimeRaiseException
MainWindow.MainWindow.Next_File%%o<MainWindow.MainWindow>
MainWindow.MainWindow.Refresh_Timer_Action%%o<MainWindow.MainWindow>o<Timer>
XojoFramework$13892
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTimer
__CFRunLoopDoTimers
__CFRunLoopRun
CFRunLoopRunSpecific
RunCurrentEventLoopInMode
ReceiveNextEventCommon
_BlockUntilNextEventMatchingListInModeWithFilter
_DPSNextEvent
-[NSApplication(NSEvent)
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]
XojoFramework$4483
XojoFramework$4484
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4483
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main
Can you help me understand what's happening ?
TIA
--
Jean-Luc Arnaud
Continue reading on narkive:
Loading...