This documentation is archived and is not being maintained.

ServerAgent.WaitHandle

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The WaitHandle property contains an internal handle used to signal that there is pending input from the Office Communications Server that the server agent needs to process.

Syntax

[C#]

public WaitHandle WaitHandle {get;}

Syntax

[Visual Basic .NET]

Public ReadOnly Property WaitHandle As WaitHandle

Remarks

Applications should wait on this handle, and whenever it is signaled, call ServerAgent.ProcessEvent. This mechanism allows applications to control the concurrency model. For example, applications can queue up work items using the ThreadPool class.

Example Code

The following example demonstrates the use of a wait handle when queuing work items in a thread pool.

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;
       }
   }
}

Requirements

Redistributable: Requires Microsoft Office Communications Server 2007 R2.

Namespace:Microsoft.Rtc.Sip

Assembly: ServerAgent (in ServerAgent.dll)

Show: