Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Way to send message to thread

What is the most efficient and fastest way to send message to a thread (not process) that run in while(1) loop in c#/.net:

  1. Using a synchronized queue (such in Blocking Queues & Thread’s Communication in C#)

  2. Running a message loop Using Application.Run of systems winforms in the thread context and before running the application.run subscribe to an event that capture the messsage in the thread context.

  3. Using socket or named pipe to send the thread a message.

In Linux I am used to do this with unix domain sockets, what is the equivalent way to do it in windows? share memory file? named pipe? What do you think?

like image 890
Eyalk Avatar asked Dec 20 '09 12:12

Eyalk


People also ask

How do I send a thread message?

To send a message within a thread, server members will need the “Send Messages in Thread” permission, which allows server members to participate within threads only - not for all general channels in the server. On the other hand, the “Send Message” permission will only apply to messages outside of threads.

How do I notify everyone in a Slack thread?

Use @channel to let everyone in a channel know about timely, relevant information. This will trigger a desktop or mobile notification for all members of the channel, whether their availability is set to active or away.

Can you move Slack messages to a thread?

It is not possible to move a slack message to a thread, but you can always reply to thread or you can attach your reply with the message you want by clicking on share message and then typing your content.


1 Answers

I'd use a producer/consumer queue, personally. That's effectively what the WinForms message loop is, just in a Windows Forms-specific way.

Note that if you're able to use .NET 4.0, there are collections built into the framework which make this very easy. In particular, using a BlockingCollection<T> wrapped round a ConcurrentQueue<T> will do what you want.

I wouldn't personally use the GeeksCafe code - I'd encapsulate the producer/consumer nature into its own class which wraps a queue, rather than treating any queue in that way via extension methods. In particular, you need all parties to handle the queue correctly, which means it's better to give it its own API in my view.

like image 70
Jon Skeet Avatar answered Oct 04 '22 12:10

Jon Skeet