ServerAgent.ProcessEvent(Object) Method

Definition

Dequeues an event from the server queue and processes it.

public:
 void ProcessEvent(System::Object ^ internalQueuedEventFlag);
public void ProcessEvent (object internalQueuedEventFlag);
Public Sub ProcessEvent (internalQueuedEventFlag As Object)

Parameters

internalQueuedEventFlag
Object

Remarks

This method implements the ThreadPool.WaitCallback delegate to make it easy for applications to use the built-in system thread pool.

This method must be called in order to dispatch messages to their corresponding event handlers (the methods registered with the respective MSPL Dispatch calls). When a server event is available for processing (a message has arrived and Dispatch has been called), the signal is received over the wait handle specified by the ServerAgent.WaitHandle property.

The following example demonstrates passing this method to a WaitCallback delegate.

public void LCServerEventHandler(ServerAgent sa)
{
   ManualResetEvent autoResetEvent = new ManualResetEvent(false);
   WaitHandle[] handleArray = new WaitHandle[] {
                                 myAppServerAgent.WaitHandle,
                                 manualResetEvent
                              };

   WaitCallback waitCallback = new WaitCallback(myAppServerAgent.ProcessEvent);

   while (true)
   {
      int signaledEvent = WaitHandle.WaitAny(handleArray);

      if (signaledEvent == 0)  // The server event wait handle (index = 0) in handleArray was signaled
      {

          // Schedule a worker thread to process the server event
          try
          {
             if (!ThreadPool.QueueUserWorkItem(waitCallBack))
             {
                 Console.WriteLine("QueueUserWorkItem fails, quitting.");
                 return;
             }

          }
          catch (Exception e)
          {
             Console.WriteLine("Unexpected exception: {0}\n{1}",
                               e.Message,
                               e.StackTrace);
          }
       }
       else // Manual reset event handle (index = 1) in handle array was signaled
       {
          Console.WriteLine("Quit handle signaled, worker will quit now\n");
          break;
       }
   }
}

Applies to