internal System.Object getLdapMessage(Integer32 msgId) { System.Object rfcMsg; // If no messages for this agent, just return null if (messages.Count == 0) { return(null); } if (msgId != null) { // Request messages for a specific ID try { // Get message for this ID // Message info = messages.findMessageById(msgId); Message info = messages.findMessageById(msgId.intValue); rfcMsg = info.waitForReply(); // blocks for a response if (!info.acceptsReplies() && !info.hasReplies()) { // Message complete and no more replies, remove from id list SupportClass.VectorRemoveElement(messages, info); info.Abandon(null, null); // Get rid of resources } else { } return(rfcMsg); } catch (System.FieldAccessException ex) { // no such message id return(null); } } else { // A msgId was NOT specified, any message will do lock (messages.SyncRoot) { while (true) { int next = indexLastRead + 1; Message info; for (int i = 0; i < messages.Count; i++) { if (next >= messages.Count) { next = 0; } info = (Message)messages[next]; indexLastRead = next++; rfcMsg = info.Reply; // Check this request is complete if (!info.acceptsReplies() && !info.hasReplies()) { // Message complete & no more replies, remove from id list SupportClass.VectorRemoveElement(messages, info); // remove from list info.Abandon(null, null); // Get rid of resources // Start loop at next message that is now moved // to the current position in the Vector. i -= 1; } if (rfcMsg != null) { // We got a reply return(rfcMsg); } else { // We found no reply here } } // end for loop */ // Messages can be removed in this loop, we we must // check if any messages left for this agent if (messages.Count == 0) { return(null); } // No data, wait for something to come in. try { System.Threading.Monitor.Wait(messages.SyncRoot, TimeSpan.FromSeconds(40)); } catch (System.Threading.ThreadInterruptedException ex) { } } /* end while */ } /* end synchronized */ } }