Have a SocketClient which communicates asynchronously with a server. SocketClient relies on Socket.BeginReceive() and Socket.EndReceive() to communicate. As incoming data is received by the Socket, it's immediately decoded by System.Text.Encoding.UTF8.GetDecoder() and parsed into strings delimited by '\n' char, which strings are then passed on to an object instantiated from class CommDataQueue; objCDQ maintains a Queue (System.Collections) of objects which include the decoded strings; besides the actual strings, there's also a DateTime time-stamp and a message ID (simple integer). So that's what the CommDataQueue queues, objects which have three data members and little in terms of methods.
Up to this point, the application runs flawlessly and FAST, because the code is pretty lean.
NOW comes the challenge: Because I want our application to give incoming data the highest priority, and convert incoming data into queued "messages" until the network buffer (Socket) is empty, I created the CommDataQueue. WHEN the Socket reports that there is NO MORE available data at the end of a receive operation, i.e. after EndReceive() returns, I would like to fire off an event to the CommDataQueue to let it know that it's ok to do other operations, like pass on the queued messages to other objects / modules in the application. [Obviously, at least one message should be queued in the CommDataQueue at the time such an event is triggered.]
The process of informing the CommDataQueue object about distributing data to other objects should be of minimal overhead! Meaning, I don't want to spawn off new threads, call the ThreadPool, or do anything which is time & resource expensive from within the SocketClient object. I want to take the LEAST EXPENSIVE / MOST EFFICIENT action to inform the CommDataQueue that it may go ahead and perform other operations, now that there is a pause in the INCOMING data stream (because Socket.Available == 0, meaning that, for the time being, there is no data waiting in the network buffer ).
Any ideas on what mechanism I should consider implementing for "sending an inexpensive message" to the CommDataQueue?