KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Fine Grain Wait for Windows
Topic Summary:
Created On: 08/31/2020 06:20 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Fine Grain Wait for Windows   - dicdoc - 08/31/2020 06:20 PM  
 Fine Grain Wait for Windows   - kkkwj - 08/31/2020 07:43 PM  
 Fine Grain Wait for Windows   - dicdoc - 08/31/2020 07:49 PM  
 Fine Grain Wait for Windows   - kkkwj - 09/01/2020 01:19 AM  
Keyword
 08/31/2020 06:20 PM
User is offline View Users Profile Print this message

Author Icon
dicdoc
Top-Tier Member

Posts: 268
Joined: 07/31/2014

When trying to refine PG LTU Macro Wait For Windows, of course it did not work. I wanted to set a max wait time, and be able to set finer waiting intervals, ie 0.1 sec. So I did this :

===

Function WaitForWindow (WindowTitle As String, MaxWaitTime As Double, WaitStep As Double) As Integer
' based on a script from the KnowBrainer Forum by PG LTU
    Dim count As Double

    count = (WaitStep)
    Do Until InStr (GetWindowTitle, WindowTitle) > 0
         DoEvents
         Wait WaitStep
         If count = MaxWaitTime Or count > MaxWaitTime Then
             WaitForWindow = 0
             Exit Function
         End If
         count = count + WaitStep
    Loop
    WaitForWindow = 1
End Function
===
But at the end I seem to wait longer than with integers and 1 intervals. I cannot understand why. I'd be gratefull for an explanation


-------------------------

Memory: 16GB Microphone Brand and Model: LFH 4000 & Flexy Mike  Operating System: win 10, latest update; Surface Book 2, Processor (CPU) Type & Speed: I7 8650 Soundcard Brand and Model: none Speech Software: Dragon Medical Practice Edition, french version: 4.2 Using KnowBrainer?:Yes

 08/31/2020 07:43 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 497
Joined: 11/05/2015

Programmatically, you should not (cannot) compare two doubles with an equals sign. In other words, "if count = MaxWaitTime" will always fail. You don't need it.

Using "if count > MaxWaitTime" alone will have the same effect.

I don't know what the original version looked like, so I can't comment on how your modifications might be different.


-------------------------

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.3, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones

 08/31/2020 07:49 PM
User is offline View Users Profile Print this message

Author Icon
dicdoc
Top-Tier Member

Posts: 268
Joined: 07/31/2014

Not sure to understand your answer correctly : 

is

If count > MaxWaitTime Then

Correct ?


-------------------------

Memory: 16GB Microphone Brand and Model: LFH 4000 & Flexy Mike  Operating System: win 10, latest update; Surface Book 2, Processor (CPU) Type & Speed: I7 8650 Soundcard Brand and Model: none Speech Software: Dragon Medical Practice Edition, french version: 4.2 Using KnowBrainer?:Yes

 09/01/2020 01:19 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 497
Joined: 11/05/2015

Yes, that would work.

 

 

The right way to compare doubles, floats, and singles is like this:

 

if (count - MaxWaitTime) > 0 then ...

 

And you were already doing that in the second clause, so the first clause "if count = MaxWaitTime" was not necessary.

 

I think your code looks ok, but your improved loop will not necessarily give you improved performance because of the DoEvents call inside the loop. Who knows how long it will take for DoEvents to do its work before it returns? If it takes a long time, then you will have to wait for it to return.

 

If it was my loop, I would 1) set "count = 0" before the loop so that I could catch fast windows on the first InStr test instead of waiting; 2) Order things this way:

 

count = 0

Do Until

- count = count + WaitTime

- if count > MaxWaitTime then

-- exit

- DoEvents

- Wait

Loop

 

Move the test for maximum time before the DoEvents call so you can escape immediately instead of doing a Wait before you exit anyway. Move the DoEvents and "Wait Waitstep" statement to the bottom of the loop. And I would probably rename the "count" variable to TotalWaitedTime to match its true meaning.

Good luck!



-------------------------

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.3, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones



Statistics
31795 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 1 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 562 guests browsing this forum, which makes a total of 563 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2020 FuseTalk™ Inc. All rights reserved.