Click or drag to resize

MessageQueue Class

A message queue used for passing messages between threads
Inheritance Hierarchy
SystemObject
  AGI.Foundation.Infrastructure.ThreadingMessageQueue

Namespace:  AGI.Foundation.Infrastructure.Threading
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.3.420.0 (24.3.420.0)
Syntax
public class MessageQueue : IDisposable

The MessageQueue type exposes the following members.

Constructors
  NameDescription
Public methodMessageQueue
Initializes a new instance.
Top
Properties
  NameDescription
Public propertyMaximumQueueLength
Gets or sets the maximum number of items that is allowed in the queue. If a thread attempts to add an item to a full queue, it will block until room is available in the queue.
Top
Methods
  NameDescription
Public methodDispose
Releases any resources associated with this instance.
Protected methodDispose(Boolean)
Releases any resources associated with this instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodPost(Object)
Adds a generic message to the message queue that is asynchronously sent to any functions that subscribe to MessageReceived.
Public methodPost(SendOrPostCallback, Object)
Adds a delegate to the message queue and immediately returns.
Public methodSend(Object)
Adds a generic message to the message queue that is synchronously sent to any functions that subscribe to MessageReceived.
Public methodSend(SendOrPostCallback, Object)
Adds a delegate to the message queue and waits until all currently queued messages and the given delegate are executed before returning.
Public methodStart
Runs the message queue in the current thread and does not return until Terminate is called.
Public methodStartInAnotherThread
Public methodStartInNewThread
Runs the message queue in a newly spawned worker thread and immediately returns. The worker thread will not be terminated until Terminate is called.
Public methodStartInNewThread(String)
Runs the message queue in a newly spawned worker thread and immediately returns. The worker thread will not be terminated until Terminate is called.
Public methodStartInThreadPoolThread
Runs the message queue in a thread pool thread and immediately returns. The worker thread will not be released back to the thread pool until Terminate is called.
Public methodTerminate

Terminates the message queue.

Any messages that are already in the queue when this method is called will be processed before the queue is terminated. This method initiates the termination and returns immediately; it does NOT wait for the termination to complete before returning. It is safe to call this method from any thread, including the thread that is processing the message queue. To wait for termination to complete, call TerminateAndWait instead. If the queue is not running when this method is called, the termination request will still be posted. That means that queue processing, once restarted, will terminate once it reaches this point in the queue.

Public methodTerminateAndWait

Terminates the message queue and waits for termination to complete.

Any messages that are already in the queue when this method is called will be processed before the queue is terminated. Unlike Terminate, this method does not return until the message queue is terminated. This method must not be called from the thread that is running the message queue. Doing so will cause a deadlock, because this method cannot return until the message queue terminates, and the queue cannot terminate until this method returns.

Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events
  NameDescription
Public eventMessageQueueStarted
Event that indicates MessageQueue has started to receive messages. If MessageQueue was started with a call to StartInAnotherThread, this event will be raised in that other thread.
Public eventMessageQueueStopped
Event that indicates MessageQueue has been stopped by a call to Terminate. If MessageQueue was started with a call to StartInAnotherThread, this event will be raised in that other thread.
Public eventMessageReceived
Event that indicates a generic message object was received. If MessageQueue was started with a call to StartInAnotherThread, this event will be raised in that other thread.
Top
See Also