in reply to Re^2: Win32::OLE and timeout
in thread Win32::OLE and timeout

BTW, I tested the proposed code and it does NOT work unless the underlying page takes more than Timeout to load and still generates events. If you test it you MUST NOT move the mouse about the IE window as that generates events that would not otherwise occur and can thus distort the results.
#!/usr/bin/perl -w use 5.006; use strict; use warnings; use Win32::OLE qw(EVENTS); use Time::HiRes qw(gettimeofday); Win32::OLE->Option(_Unique => 1); sub IENavigate( $ ); $| = 1; # do not buffer output my $IE; my $IETimeout = 60; my $timeAtStart; #new global var my @urls = qw( http://www.google.com http://www.cnn.com/ ); # start ie, connect to events, make IE visible, connect alarm handler $IE = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer.Application\n"; Win32::OLE->WithEvents($IE,\&IEEvent,"DWebBrowserEvents2"); $IE->{visible} = 1; $SIG{ALRM} = \&IEAlarm; # visit some URLs foreach (@urls){ print "Navigate to $_\n"; my $seconds = IENavigate( $_ ); print "took $seconds\n"; } # we're done print "Done\n"; # kill this IE $IE->Quit(); exit; # ################################################################### # sub IENavigate( $ ) { my $url = shift; my $seconds = 0; print "IENavigate $url\n"; $timeAtStart = time unless ($timeAtStart); alarm $IETimeout; $IE->navigate($url); Win32::OLE->MessageLoop(); print "Finished Blocking\n"; return; } sub IEEvent(){ my ($Obj,$Event,@Args) = @_; if (($IETimeout) && ($timeAtStart) && (time > ($timeAtStart + $IET +imeout) )) {&IEAlarm(17)}; print "IEEvent '$Event'\n"; } sub IEAlarm(){ my $sig = shift; print "IEAlarm $sig\n"; Win32::OLE->QuitMessageLoop(); }