Sign in to follow this  
Followers 0
MisterBates

Adjusting "sleep" time depending on PC utilisation

10 posts in this topic

In my latest script I'm trying to extract sender/receiver email names/addresses from Outlook Express, to be able to send an "I'm changing my email address" message to people that I've communicated with recently. I did think about simply using the address book, but it has many old addresses in, so thought to get a more recent list based on recent communciations...

Anyway, as OE doesn't have a public API, I'm having to do all this by interacting with the OE user interface. I've got to the point where I can start OE, switch to the folder pane, and send {right} and {down} keys to navigate the folders. I'm using the OE title bar to understand which folder I'm processing - OE updates the title based on the folder being veiwed.

To give OE time to update the title, I've had to insert some sleep() statements. Problem is, if my PC is not doing much, the duration I'm using (700ms) results in a script that runs very slowly. But if my PC is doing some other stuff in the background, 700ms is too short and I risk missing folders, as OE has not had time to update the window title.

Anyone any thoughts about how I could base the sleep duration on the relative loading of my PC - for a shorter sleep if my PC is not heavily loaded, and a longer sleep if it is?

Share this post


Link to post
Share on other sites



If you are waiting for something to change, you should look into:

PixelChecksum

Put it in a loop until it has changed, then you know the title bar has changed.

Share this post


Link to post
Share on other sites

If you are waiting for something to change, you should look into:

PixelChecksum

Put it in a loop until it has changed, then you know the title bar has changed.

Thanks for a quick response!

Unfortunately, to process the folder list I send {right} then wait to see if the title changes (which it will when there are subfolders), and if it doesn't then I send {down} (to move to the next folder at the same or higher hierarchy level.

So the problem is to know when to send the {down} (as there are no subfolders) which can't be detected as a change.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$oldtitle = WinGetTitle("[CLASS:Outlook Express Browser Class]")
While WinGetTitle("[CLASS:Outlook Express Browser Class]") == $oldtitle
    Sleep(100)
WEnd

or something.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

If you are pressing right in the "all mail folders" pane, and there are no subfolders to go {right} to then the pixelChecksum of the "all mail folders" pane will have not changed. If the folder that you are on does have a subfolder then your pixelchecksum will have changed when you hit right. You could also try to detect the "[+]", but that could be pretty complex.

Share this post


Link to post
Share on other sites

$oldtitle = WinGetTitle("[CLASS:Outlook Express Browser Class]")
While WinGetTitle("[CLASS:Outlook Express Browser Class]") == $oldtitle
    Sleep(100)
WEnd

or something.

Thanks Siao. Looks like we crossed in the "posts" - see my previous reply: sometimes the title will change, sometimes not. I need to detect both situations.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@Saio, if the folder he is on does not have subfolders then his code would be forever paused

I think that the pixelchecksum on the all mail folders pane would work fine... Do you need me to post code?

Edited by danwilli

Share this post


Link to post
Share on other sites

If you are pressing right in the "all mail folders" pane, and there are no subfolders to go {right} to then the pixelChecksum of the "all mail folders" pane will have not changed. If the folder that you are on does have a subfolder then your pixelchecksum will have changed when you hit right. You could also try to detect the "[+]", but that could be pretty complex.

Ooop :"> Next time I'll RTFM before posting a reply. I'll try it and let you know if it works ...

Share this post


Link to post
Share on other sites

I think that the pixelchecksum on the all mail folders pane would work fine

I got the code working, and found a more reliable way to do so. Sending {NUMPADADD} will expand subfolders if there are any, else it has no effect. So I send {NUMPADADD}, then get the pixelchecksum, then send {DOWN}. That way, if there is a folder below the one I saw previously, the checksum changes. If not, it doesn't - and I know I'm at the end of the folder list. I added a small delaying loop of up to 250ms between the controlsends and the pixelchecksums ... this gives OE time to repaint.

Code extract:

ControlSend($hOE, "", $hPane, "{NUMPADADD}"); Expand subfolders (if any)
    $iChecksum = _OE_PaneChecksum($hOE, $hPane)
    ControlSend($hOE, "", $hPane, "{DOWN}"); Move to next folder
    $iI = 0
    while ($iI < 5) and (_OE_PaneChecksum($hOE, $hPane) = $iChecksum)
        sleep(50)
        $iI += 1
    WEnd

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0