This documentation is archived and is not being maintained.

Queued Components

The COM+ Queued Components service provides an easy way to invoke and execute components asynchronously using Microsoft Message Queuing. Processing can occur without regard to the availability or accessibility of either the sender or receiver.

To use this service, the class must derive directly or indirectly from the System.EnterpriseServices.ServicedComponent class.

The MaxListenerThreads property indicates the maximum number of concurrent Queued Components listener threads. The valid range for this value is 0 through 1000. For a newly created application, the setting is derived from the algorithm currently used for determining the default number of listener threads: 16 multiplied by the number of CPUs in the server. This value does not dictate the number of threads running at all times, simply the maximum number of possible threads. On an idle server, there would be only one thread running until more messages were found in the queue. Then the server would create more threads as needed until it reaches the MaxListenerThreads value. The following example sets the maximum number of Queued Components listener threads to 64.

Note   The string supplied to the Marshal.BindToMoniker method can contain optional parameters to specify the computer name and other information. Please refer to the "Developing Queued Components" section of the Platform SDK for more information.
<ApplicationQueuingAttribute(QueueListenerEnabled := _ 
true, MaxListenerThreads :=  64 )>
[ApplicationQueuingAttribute(QueueListenerEnabled = true, MaxListenerThreads =  64 )]

The following two-part example shows how to implement a QComponent class on the server to display a message asynchronously and uses a client to invoke the DisplayMessage method on a Queued Component.


Imports System.Reflection
Imports System.EnterpriseServices
Imports System

<assembly: ApplicationName("QCDemoSvr")>
<assembly: ApplicationActivation(ActivationOption.Server)>
<assembly: ApplicationQueuing(Enabled := True, _
            QueueListenerEnabled := True)>
<assembly: AssemblyKeyFile("QCDemoSvr.snk")>

Namespace QCDemo
   Public Interface IQComponent
      Sub DisplayMessage(msg As String)
   End Interface 
   <InterfaceQueuing(Interface := "IQComponent")> _
   Public Class QComponent 
   Inherits ServicedComponent Implements IQComponent 
          Public Sub DisplayMessage(msg As String) implements _
             MessageBox.Show(msg, "Processing message")
          End Sub 'DisplayMessage
   End Class 
End Namespace 
using System.Reflection;
using System.EnterpriseServices;

[assembly: ApplicationName("QCDemoSvr")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationQueuing(Enabled=true, QueueListenerEnabled=true)]
[assembly: AssemblyKeyFile("QCDemoSvr.snk")]

namespace QCDemo
    public interface IQComponent 
        void DisplayMessage(string msg);

 [InterfaceQueuing(Interface = "IQComponent"]
    public class QComponent  : ServicedComponent, IQComponent
        public void DisplayMessage(string msg)
            MessageBox.Show(msg, "Processing message");


Protected Sub Send_Click(sender As Object, e As System.EventArgs) _
Handles send.Click
      Dim iQc As IQComponent = Nothing
            iQc = CType(Marshal.BindToMoniker("queue:/new:QCDemo.QComponent"), _
      Catch l as Exception
            Console.Writeline("Caught Exception: " & l.Message)
      End Try
End Sub 'Send_Click
protected void Send_Click (object sender, System.EventArgs e)
      IQComponent iQc = null;
            iQc = (IQComponent)      Marshal.BindToMoniker("queue:/new:QCDemo.QComponent");
            MessageBox.Show("Cannot create Queued Component");
      iQc.DisplayMessage (messageToSend.Text);

See Also

Summary of Available COM+ Services | System.EnterpriseServices Namespace