Hello folks, thanks in advance...
I'm writing/running some very small non-UI programs under B4J, hoping that the core stuff I'm playing with is the same for B4A, as that is my ultimate goal, to develop an Android app.
So, I was playing around with timers, getting familiar with those.In my 'x_Tick' loop (1000 ms delay), I just increment a global integer 'count' variable. Outside, I check if 'count' is less than 10 -- if it is, I Log the value of count, then Sleep for 1000 ms; otherwise, the loop ends. Trouble is, if and when I call Sleep, the program ends. Got rid of the timer stuff (we'll come back to you later...), to focus on the Sleep trouble, so my code is the following:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
Private count As Int = 121
Log( "A: " & count )
Try
Sleep(1)
Catch
Log( "in Catch" )
Log(LastException)
End Try
Log( "B: " & count )
count = count + 1
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
So, I see the "Log A: 121" message in the output, but not the "B:" one. There are no error or warning messages, either building or running. If I comment out the "Sleep( 1 )" statement, I see the "B:" message, as well as the "A:" one. If I put the Try/Catch block (and few lines below, the "Loop" statement ends up under the line that increments count) into a Do While count < 10 loop, it runs fine, count goes from 1-10 with Sleep commented out; otherwise, I see the "A: 121" message just once (first time through the loop), then nothing (no "B: 121", no messages with higher values of count); I just get what seems to be this normal exit message (?):
Program terminated (StartMessageLoop was not called).
Tried calling Sleep with several different delay values: 0, 1, 10. 100, 1000, 10000 == all behaved the same, terminating execution.
Added the Try/Catch block after I was completely puzzled -- the Catch block never gets called, with or without Sleep() commented out.
Tried declaring count with 'Dim" instead of 'Private' -- no difference.
Any ideas? Something very basic I'm missing/overlooking?
Thanks,
Jeff
I'm writing/running some very small non-UI programs under B4J, hoping that the core stuff I'm playing with is the same for B4A, as that is my ultimate goal, to develop an Android app.
So, I was playing around with timers, getting familiar with those.In my 'x_Tick' loop (1000 ms delay), I just increment a global integer 'count' variable. Outside, I check if 'count' is less than 10 -- if it is, I Log the value of count, then Sleep for 1000 ms; otherwise, the loop ends. Trouble is, if and when I call Sleep, the program ends. Got rid of the timer stuff (we'll come back to you later...), to focus on the Sleep trouble, so my code is the following:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
Private count As Int = 121
Log( "A: " & count )
Try
Sleep(1)
Catch
Log( "in Catch" )
Log(LastException)
End Try
Log( "B: " & count )
count = count + 1
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
So, I see the "Log A: 121" message in the output, but not the "B:" one. There are no error or warning messages, either building or running. If I comment out the "Sleep( 1 )" statement, I see the "B:" message, as well as the "A:" one. If I put the Try/Catch block (and few lines below, the "Loop" statement ends up under the line that increments count) into a Do While count < 10 loop, it runs fine, count goes from 1-10 with Sleep commented out; otherwise, I see the "A: 121" message just once (first time through the loop), then nothing (no "B: 121", no messages with higher values of count); I just get what seems to be this normal exit message (?):
Program terminated (StartMessageLoop was not called).
Tried calling Sleep with several different delay values: 0, 1, 10. 100, 1000, 10000 == all behaved the same, terminating execution.
Added the Try/Catch block after I was completely puzzled -- the Catch block never gets called, with or without Sleep() commented out.
Tried declaring count with 'Dim" instead of 'Private' -- no difference.
Any ideas? Something very basic I'm missing/overlooking?
Thanks,
Jeff