I'm writing a c# component that will only be used internally at my company. The component encapsulates communication with a number of servers that particular desktop applications need to communicate with. The servers can send unsolicited messages to the component, which are 'caught' in a separate thread.
I want the majority of this component to execute under the context of its creating thread. I do not wish the separate message thread to do any message processing. Instead, I would like to notify the main thread that there is a message awaiting processing. The reason for wanting to execute under the context of the creating thread, is that users of the library may not know multi-threading, and I'd like to be able to synchronize all operations if possible.
Is there an easy way of signaling a running thread? The main thread will be doing all kinds of constant processing, and the message thread will be constantly spinning waiting for messages. It may be worth noting that the message thread is encapsulated in a third party library. Once it receives a message, it executes a callback. I'd like the callback to do something like mainthread.notify(message).
Edit: Sorry I wasn't too clear on what I want the main thread to do. I don't want the main thread to immediately process the message sent by the message thread. I want it to process the message at some time in the near future (like how the WinForms Message Loop works).
Edit 2:
The scenario:
Console App created on Thread1
Thread2 created, which spins listening for Messages
Console App runs as normal
Message arrives on Thread2
Thread2 fires event MessageReady(sender, message)
Thread2 continues spinning
At the earliest convenience, Thread1 processes the message from MessageReady
I've done some reading, and it appears that marshaling code to another thread is quite a difficult manner, and I'm doubting that synchronizing this process would be worth the effort.