Ding Ding Ding! I have a 100ms sleep in the UserInterface update. When I commented that line out, suddenly the 15 second sleep started working⦠sort of.
'Logstring = "Pausing 15 seconds for Prinect processing" _
'+ EndOfLine + "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
'Me.AddUserInterfaceUpdate("Transaction":Logstring)
'Me.Sleep(15000,False)
static traceLabel As Integer
traceLabel = traceLabel + 1
// log a message and current time
Var dt As DateTime = DateTime.Now
System.DebugLog(dt.SQLDateTime + " trace start 15secs #"+traceLabel.ToString)
Me.Sleep(15000,False)
dt = DateTime.Now
System.DebugLog(dt.SQLDateTime + " trace end 15secs #"+traceLabel.ToString)
Resulted in these times each pause being 15 seconds:
1:16:30 PM : PrinectUpdateXJDF.exe Launched
1:17:34 PM : 2024-03-05 13:17:34 trace start 15secs #1
1:17:49 PM : 2024-03-05 13:17:49 trace end 15secs #1
1:17:52 PM : 2024-03-05 13:17:52 trace start 15secs #2
1:18:07 PM : 2024-03-05 13:18:07 trace end 15secs #2
1:18:10 PM : 2024-03-05 13:18:10 trace start 15secs #3
1:18:25 PM : 2024-03-05 13:18:25 trace end 15secs #3
1:18:38 PM : PrinectUpdateXJDF.exe Ended
: Process Completed.
When I uncommented the following line for showing the Logstring below
Yes Windows. It appears it is the act of using UserInterfaceUpdate just before a sleep that is causing the inconsistency in sleep time. Not using it I get the full sleep. Still puzzling out how to log what I need and still get the full 15 seconds.
the 100ms sleep was to insure the logging happened without delay yielding some time to the UI.
Try logging with Print(), this goes to a log that you can view in Lifeboat or stdout when running by other means. This includes the benefit of not being tied to a Session.
I log to a file, so it doesnβt need to go via UserInterfaceUpdate. But the main thing is to actually have a logging mechanism. Something I learnt in the 1970s.
I log Transactions and Exceptions to separate log files but display what Iβm logging in the UI as itβs happening so that the folks monitoring the application can validate that the app is processing, paused, etc.
The disturbing thing is your trace start and trace end are not in sequence, ie., you have two trace start back to back before another trace end. Is something kicking off another instance of the thread?
It isnβt supposed launch another thread, but as wonky as it is performing Iβve decided to re-engineer the entire process flow.
What the app does is:
every 60 seconds it checks a hot folder for files.
If one or more files exists it validates a job type against each file name using regular expressions.
the app then select the first file in the validated list of files to be the one to process.
The file is a text file with one job number per line.
The thread processes the job numbers serially to request current job specs via GET
the app reads the XML returned and then formats the specs into a specific XML called XJDF and sends the XJDF file path to a prepress server using XJMF.
The rest of the flow is rinse and repeat until no jobs left to process. This is the point that the thread re-enable the hot folder timer, the thread ends and the process will repeat until there are no files left or wait until new files arrive.
Iβm considering re-engineering the workflow to serially launch a thread for each job that will run to completion before launching the next thread.
It would look differently if you added the times to a dictionary sent with AddUserInterfaceUpdate and output that property too. A UserInterfaceUpdate does not fire directly after an Addβ¦, thatβs why the GUI event has an array of dictionaries although you always send one. There might be an unpredictable delay between adding and updating.
This only happened when I uncommented the line for the UI update. Iβm now convinced the UserInterfaceUpdate does strange things to the thread execution order. I may have to go back to an older way of logging from a thread.
There definitely is wonky unpredictability going on in this app that I havenβt encountered before in other places Iβve used it. Iβm going to eliminate using it in favor of another method. I plan to have an array to stick the log lines in and a timer will just periodically read and clear the log lines and update the UI outside of the thread.
I wouldnβt be impressed if Xojo ignored some events if the system were too busy when Xojo expected to fire it.
If he used System.DebugLog, I remember observing something like that using System.DebugLog, I guess it uses timers and not queues, and I guess some timer events are discarded when missing the mark.
Maybe using his own immediate log to file methods the missing lines show up.
I did not test if Xojo fixed that, but some versions ago you could lose final Updates when the thread finishes before the last UserInterfaceUpdate fires. Thatβs why I am using a custom thread subclass that keeps the thread alive until there are no more updates. But I never have seen missing parts in between when I iterate through the result array.