Sie sind auf Seite 1von 3

7/22/13

Queued Components

Queued Components
.NET Framework 1.1 This topic has not yet been rated 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. VB < A p p l i c a t i o n Q u e u i n g A t t r i b u t e ( Q u e u e L i s t e n e r E n a b l e d: =_ t r u e ,M a x L i s t e n e r T h r e a d s: = 6 4) > [ C # ] [ A p p l i c a t i o n Q u e u i n g A t t r i b u t e ( Q u e u e L i s t e n e r E n a b l e d=t r u e ,M a x L i s t e n e r T h r e a d s= 6 4) ]

The following two-part example shows how to implement a Q C o m p o n e n tclass on the server to display a message asynchronously and uses a client to invoke the DisplayMessage method on a Queued Component. Server VB I m p o r t sS y s t e m . R e f l e c t i o n I m p o r t sS y s t e m . E n t e r p r i s e S e r v i c e s I m p o r t sS y s t e m < a s s e m b l y :A p p l i c a t i o n N a m e ( " Q C D e m o S v r " ) > < a s s e m b l y :A p p l i c a t i o n A c t i v a t i o n ( A c t i v a t i o n O p t i o n . S e r v e r ) > < a s s e m b l y :A p p l i c a t i o n Q u e u i n g ( E n a b l e d: =T r u e ,_ Q u e u e L i s t e n e r E n a b l e d: =T r u e ) > < a s s e m b l y :A s s e m b l y K e y F i l e ( " Q C D e m o S v r . s n k " ) > N a m e s p a c eQ C D e m o P u b l i cI n t e r f a c eI Q C o m p o n e n t S u bD i s p l a y M e s s a g e ( m s gA sS t r i n g )
msdn.microsoft.com/en-IN/library/cwd2fx9t(d=printer,v=vs.71).aspx 1/3

7/22/13

S u bD i s p l a y M e s s a g e ( m s gA sS t r i n g ) E n dI n t e r f a c e

Queued Components

< I n t e r f a c e Q u e u i n g ( I n t e r f a c e: =" I Q C o m p o n e n t " ) >_ P u b l i cC l a s sQ C o m p o n e n t I n h e r i t sS e r v i c e d C o m p o n e n tI m p l e m e n t sI Q C o m p o n e n t P u b l i cS u bD i s p l a y M e s s a g e ( m s gA sS t r i n g )i m p l e m e n t s_ I Q C o m p o n e n t . D i s p l a y M e s s a g e M e s s a g e B o x . S h o w ( m s g ," P r o c e s s i n gm e s s a g e " ) E n dS u b' D i s p l a y M e s s a g e E n dC l a s s E n dN a m e s p a c e [ C # ] u s i n gS y s t e m . R e f l e c t i o n ; u s i n gS y s t e m . E n t e r p r i s e S e r v i c e s ; [ a s s e m b l y :A p p l i c a t i o n N a m e ( " Q C D e m o S v r " ) ] [ a s s e m b l y :A p p l i c a t i o n A c t i v a t i o n ( A c t i v a t i o n O p t i o n . S e r v e r ) ] [ a s s e m b l y :A p p l i c a t i o n Q u e u i n g ( E n a b l e d = t r u e ,Q u e u e L i s t e n e r E n a b l e d = t r u e ) ] [ a s s e m b l y :A s s e m b l y K e y F i l e ( " Q C D e m o S v r . s n k " ) ] n a m e s p a c eQ C D e m o { p u b l i ci n t e r f a c eI Q C o m p o n e n t { v o i dD i s p l a y M e s s a g e ( s t r i n gm s g ) ; } [ I n t e r f a c e Q u e u i n g ( I n t e r f a c e=" I Q C o m p o n e n t " ] p u b l i cc l a s sQ C o m p o n e n t :S e r v i c e d C o m p o n e n t ,I Q C o m p o n e n t { p u b l i cv o i dD i s p l a y M e s s a g e ( s t r i n gm s g ) { M e s s a g e B o x . S h o w ( m s g ," P r o c e s s i n gm e s s a g e " ) ; } } } Client VB P r o t e c t e dS u bS e n d _ C l i c k ( s e n d e rA sO b j e c t ,eA sS y s t e m . E v e n t A r g s )_ H a n d l e ss e n d . C l i c k D i mi Q cA sI Q C o m p o n e n t=N o t h i n g T r y i Q c=C T y p e ( M a r s h a l . B i n d T o M o n i k e r ( " q u e u e : / n e w : Q C D e m o . Q C o m p o n e n t " ) ,_ I Q C o m p o n e n t ) C a t c hla sE x c e p t i o n C o n s o l e . W r i t e l i n e ( " C a u g h tE x c e p t i o n :"&l . M e s s a g e ) E n dT r y i Q c . D i s p l a y M e s s a g e ( m e s s a g e T o S e n d . T e x t ) M a r s h a l . R e l e a s e C o m O b j e c t ( i Q c ) E n dS u b' S e n d _ C l i c k [ C # ] p r o t e c t e dv o i dS e n d _ C l i c k( o b j e c ts e n d e r ,S y s t e m . E v e n t A r g se ) { I Q C o m p o n e n ti Q c=n u l l ;

msdn.microsoft.com/en-IN/library/cwd2fx9t(d=printer,v=vs.71).aspx

2/3

7/22/13

I Q C o m p o n e n ti Q c=n u l l ; t r y { i Q c=( I Q C o m p o n e n t ) M a r s h a l . B i n d T o M o n i k e r ( " q u e u e : / n e w : Q C D e m o . Q C o m p o n e n t " } c a t c h { M e s s a g e B o x . S h o w ( " C a n n o tc r e a t eQ u e u e dC o m p o n e n t " ) ; } i Q c . D i s p l a y M e s s a g e( m e s s a g e T o S e n d . T e x t ) ; M a r s h a l . R e l e a s e C o m O b j e c t ( i Q c ) ; }

Queued Components

See Also
Summary of Available COM+ Services | System.EnterpriseServices Namespace
2013 Microsoft. All rights reserved.

msdn.microsoft.com/en-IN/library/cwd2fx9t(d=printer,v=vs.71).aspx

3/3

Das könnte Ihnen auch gefallen