I am using Apple Event Mechanism.. Whenever some action occurs on the client side I launch the server application and then send the event to that aplication..

As Mac OS classic uses cooperative scheduling, after launching the application, I am calling WaitNextEvent method.. But the event is being sent before the application is being launched.. I am using FlushEvents method just after launching the application.. Eventhen I am facing the same problem..

I am putting the code below.. Can anybody help me on this??

ProcessSerialNumber psn;
OSStatus i, err;
AppleEvent event = { typeNull, 0 };
AppleEvent reply = { typeNull, 0 };
AEAddressDesc target = { typeNull, 0 };
AEDescList creator_list = { typeNull, 0 };
AEDescList extension_list = { typeNull, 0 };
AEIdleUPP MyIdleUPP;
#if 0 // pick one
err = LaunchDocuBOMJavaLinkX();
#else
EventRecord event1;
err = LaunchDocuBOMJavaLinkClassic();
FlushEvents(everyEvent,0);
WaitNextEvent(autoKeyMask,&event1,1200,NULL);
#endif

if ( ! err ) err = ProcessUtils::FindProcessBySignature( kDocuBOMCreatorCode, psn );

if ( ! err ) err = AECreateDesc( typeProcessSerialNumber, &psn, sizeof(psn), &target );

if ( ! err ) err = AECreateAppleEvent( kAEDocuBOMEventClass, kAECheckOut, &target, kAutoGenerateReturnID, kAnyTransactionID, &event );

if ( ! err && ( inArrayOfCreatorCodesToOpen || inArrayOfFilenameExtensionsToOpen ) ) {
if ( inArrayOfCreatorCodesToOpen ) {
err = AECreateList( nil, 0, false, &creator_list );
for ( i = 0; ! err && inArrayOfCreatorCodesToOpen[ i ]; ++i ) {
err = AEPutPtr( &creator_list, 0, typeType, &inArrayOfCreatorCodesToOpen[ i ], sizeof(OSType) );
}
}
if ( inArrayOfFilenameExtensionsToOpen) {
err = AECreateList( nil, 0, false, &extension_list );
for ( i = 0; ! err && inArrayOfFilenameExtensionsToOpen[ i ]; ++i ) {
err = AEPutPtr( &extension_list, 0, typeChar, inArrayOfFilenameExtensionsToOpen[ i ], long(strlen( inArrayOfFilenameExtensionsToOpen[ i ] ) + 1) );
}
}
}
if ( ! err && creator_list.descriptorType != typeNull ) err = AEPutParamDesc( &event, keyCreatorCodeList, &creator_list );
if ( ! err && extension_list.descriptorType != typeNull ) err = AEPutParamDesc( &event, keyFilenameExtensionList, &extension_list );

if ( ! err ) err = GetCurrentProcess( &psn );
if ( ! err ) err = AEPutParamPtr( &event, keyDirectObject, typeProcessSerialNumber, &psn, sizeof(ProcessSerialNumber) );

MyIdleUPP= NewAEIdleUPP(MyAEIdleCallback);
if ( ! err ) err = AESend( &event, &reply, kAEWaitReply, kAEHighPriority, kNoTimeOut, MyIdleUPP, nil );

AEDisposeDesc( &extension_list );
AEDisposeDesc( &creator_list );
AEDisposeDesc( &target );
AEDisposeDesc( &event );
AEDisposeDesc( &reply );

return err;