I run several Java application through Xojo shell(Windows) and the ending time of each job is different.
When once job is done, I should wait 10 seconds then I need to do one more step to finish the job.
Question:
How can I start the post step after 10 seconds?
My windows application should be responsive while it is waiting for 10 seconds.
I have tried to run below code (Michel B) in a method but it complains that ‘self’ doesn’t mean anything.
Can you let me know what should I modify, or any idea to accomplish my requirement?
dim old as double = microseconds
for i as integer = 1 to Mil*1000
App.YieldToNextThread
self.refresh
if microseconds-old >= Mil*1000 then exit
next
return
[quote=266416:@changwon lee]I run several Java application through Xojo shell(Windows) and the ending time of each job is different.
When once job is done, I should wait 10 seconds then I need to do one more step to finish the job.
[/quote]
Xojo already yields at loop boundaries, so the For loop might yield, right before your call to App.YieldToNextThread
The Yield won’t yield for long, and if there is nothing else going on in your app, it may yield for less than 1 msec.
Self.refresh is going to refresh the entire object (probably a Window?)
This code may end up calling Self.Refresh more than a thousand times a second.
What you should really do is either use a Timer, or just put this code in a Thread subclass:
Run
... do whatever you need to set things up...
dim durationMsec as double = sleepDuration * 1000
me.sleep durationMsec
... take your actions after sleeping ...
There are probably a bunch of better ways to accomplish this, however.
[quote=266545:@changwon lee]Timer works as expected.
By the way, I need to pass one more argument into a Timer action to distinguish my jobs.
Tried below code but got an error ‘Not enough arguments’.
Can you let me know how to fix it?
I am not sure how AddHandler works.
[code]
DiffTimer_Action(sender As Timer, one_more_arg as integer)
InitTimer method
DiffTimer(timerCounter) = New Timer
DiffTimer(timerCounter).Period = inflight_latency
AddHandler DiffTimer(timerCounter).Action, AddressOf DiffTimer_Action(one_more_arg)
[/code][/quote]
You’re hitting this at the wrong end. Timer.Action does not accept any arguments. You cannot change that. What you need to do is create a subclass of Timer and pass the argument to New Timer() by creating a new Constructor method that accepts an argument. Alternately, you could store the value in a global variable, but that is a bit untidy.
Thank you Michael Diehr/Tim Hare for the detail explanation.
With Wayne’s advice, I just tried to go over “CallLater” method which is provided by default in Xojo.
It is really what I wanted to get!!!
With just one line, I can call my post method, and even I can pass a argument.
Actually, I just need to call the method once.
Below one does everything I need now. Really great.