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

Hello everyone,

I have a perl code for monitoring news title.
I use Win32::OLE to access news server.
And news title is updated at real time.
I need keep login state to receive news title.
Login event is also implemented using Win32::OLE

I want execute another code during receiving news title at real time.
In the below example, I want to print something after &get_news.
But I couldn't see print message because my code is stuck at "Win32::OLE->MessageLoop" to receive event of news title update.

How can I execute another code during receiving news update real time?

The below code is brief version of my code, not full code.
==================================================
use Win32::OLE qw(EVENTS); &Login; &get_news; print "something printed during receiving news title at real time\n"; sub get_news { my $XAReal = Win32::OLE->new('XA_DataSet.XAReal'); $XAReal->SetFieldData('InBlock','nwcode','NWS001'); my $XARealEvents = sub { my ( $obj, $event, @args ) = @_; # 1: OnReceiveRealData if ($event) { my $time = $obj->GetFieldData('OutBlock', 'time'); my $title = $obj->GetFieldData('OutBlock', 'title'); print "[$time] $title\n"; } }; Win32::OLE->WithEvents( $XAReal, $XARealEvents, '{16602768-2C96-4D93-984B-E36E7E35BFBE}', ); $XAReal->AdviseRealData; Win32::OLE->MessageLoop; } sub Login { $XASession = Win32::OLE->new('XA_Session.XASession'); $XASessionEvents = sub { my ($obj, $event, @args) = @_; # 1: OnLogin # 2: OnLogout # 3: OnDisconnect if($event == 1) { print "Login success\n"; Win32::OLE->QuitMessageLoop; } else { die "\nLogin ERROR!\n"; } }; Win32::OLE->WithEvents( $XASession, $XASessionEvents, '{6D45238D-A5EB-4413-907A-9EA14D046FE5}', ); $XASession->Login($user, $pass); Win32::OLE->MessageLoop; }

Replies are listed 'Best First'.
Re: another code execution during Win32::OLE->MessageLoop
by marinersk (Priest) on Jul 16, 2015 at 17:02 UTC

    I'm not sure I understand your meaning.

    Is the fetch taking so long that you'd like to see other work getting down whilst it is busy fetching? Then something akin to forkor use of threads might be your path toward solution.

    If you just want get_news()to do more things when it fetches, write new stuff into that subroutine.

Re: another code execution during Win32::OLE->MessageLoop ( SpinMessageLoop
by Anonymous Monk on Jul 16, 2015 at 21:20 UTC

    But I couldn't see print message because my code is stuck at "Win32::OLE->MessageLoop" to receive event of news title update. How can I execute another code during receiving news update real time?

    Don't use MessageLoop, use SpinMessageLoop to make your own verision of MessageLoop

    ... Win32::OLE->SpinMessageLoop; ... Win32::OLE->SpinMessageLoop; while(1){ Win32::OLE->SpinMessageLoop; sleep 1; last if $quitting; } ... Win32::OLE->SpinMessageLoop;