puff has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on an application that uses OLE automation. I need to execute an OLE message loop
Win32::OLE->MessageLoop();
to allow some events to occur. Durring the events, my perl event routine is being called OK and eventually determines that it is likely that the OLE object has done it's job. Unfortunately, that may not be true as there may be a few more OLE events yet to come. I'm trying to deal with this possibility by
alarm 1;
inside the ole event handler and then stoping the OLE message loop within the alarm handler. But the alarm handler is never getting executed! Can anyone provide any insight? Is there a timer like mechanism that is consistent with the ole message loop? Is there some way I can ask that my OLE event routine be invoded after a delay with a specified data load?

Replies are listed 'Best First'.
Re: Win32::OLE and alarm
by Trix606 (Monk) on Nov 03, 2005 at 20:20 UTC
    Have you tried using: Win32::Sleep() to create the delay?
      I don't think sleep can help (native or Win32) since I need to exit the event routine so that the OLE event loop can continue to run and possibly send additional events.

      I think what I'm looking for is a perl callback timer mechanism that is consistent with Win32::OLE. A com object callback timer might work.
        What about using Win32::OLE->SpinMessageLoop() and creating your own timer loop.
Re: Win32::OLE and alarm
by InfiniteSilence (Curate) on Nov 03, 2005 at 20:46 UTC
    I think what you are looking to do is to break out of the message loop (or QuitMessageLoop()) which is described in this article.

    Celebrate Intellectual Diversity

      I know how to quit the message loop, that's not the issue. The problem is in determining when to quit the message loop.

      As things stand now, I've got a Perl event routine that executes when the OLE object issues an event. The perl event routine monitors these events and determines that it is likely that the OLE object has completed it's work.

      If I was certain that this was true, I could just quit the message loop and all would be well. Unfortunately, I can not be certain that the OLE object is indeed done until I wait for a bit while allowing the message loop to continue to run since there may be additional events. So what I was hoping would work was to set an alarm for a bit later. If the alarm fires, then there have been no more OLE events and I am indeed done, so I can stop the OLE message loop. If on the other hand there is another OLE event, the OLE event routine catches it since the OLE event loop is still running and I reset the alarm and wait for another potential completion condition to exist.

      I could do this with perl's alarm BUT while the OLE message loop is running, alarm doesn't work! So what I need is an alarm like thing that will work while the OLE message loop is active.

      Either that or some other workaround for this OLE message loop behavior.