Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If performance is what you're after, and async at its finest level, I suggest looking into Completion Ports. This is what is ultimately underneath, hidden in the Windows Kernel, and it's awesome. When I used them, I used C++, even found a Kernel bug because of it, <strong>but</strong> I was limited to the language. </p> <p>I've seen <a href="http://www.codeproject.com/KB/cs/managediocp.aspx" rel="nofollow">this article</a> on CodeProject which might be worth exploring to see where you can take your idea further and/or use the code that's there.</p> <p>The nature of Completion ports is to work on callbacks. That is, in general, you "put" a request in the queue, and when something lands there, the request is read and the callback specified is read. It is in fact, a queue, but like I said, at the lowest (manageable) level (before getting almost on metal).</p> <p><strong>EDIT:</strong> I've written a sort of a FTP server/client testing utility with Completion ports, so the base process is the same - reading and writing of commands in a <em>queuable</em> fashion. Hope it helps.</p> <p><strong>EDIT #2:</strong> Ok, here's what I would do, based on your feedback and comments. I would have an "outgoing queue", <code>ConcurrentQueue&lt;Message&gt;</code>. You can have a separate thread for sending messages by dequeueing each message. <em>Note, if you want it a bit more "safe", I suggest peeking at the message, sending it, then dequeuing it.</em> Anyway, the Message class can be internal, and look something like this:</p> <pre><code>private class Message { public string Command { get; set; } ... additonal properties, like timeouts, etc. ... } </code></pre> <p>In the singleton class (I'll call it <code>CommunicationService</code>), I'd also have a <code>ConcurrentBag&lt;Action&lt;Response&gt;&gt;</code>. This is now where the fun starts :o). When a separate concern wants to do something, it registeres itself, for example, if you have a <code>TemepratureMeter</code> I would have it do something like this:</p> <pre><code>public class TemperatureMeter { private AutoResetEvent _signal = new AutoResetEvent(false); public TemperatureMeter { CommunicationService.AddHandler(HandlePotentialTemperatureResponse); } public bool HandlePotentialTemperatureResponse(Response response) { // if response is what I'm looking for _signal.Set(); // store the result in a queue or something =) } public decimal ReadTemperature() { CommunicationService.SendCommand(Commands.ReadTemperature); _signal.WaitOne(Commands.ReadTemperature.TimeOut); // or smth like this return /* dequeued value from the handle potential temperature response */; } } </code></pre> <p>And now, in your CommunicationService, when you receive a response, you simply to a</p> <pre><code>foreach(var action in this._callbacks) { action(rcvResponse); } </code></pre> <p>Voila, separation of concerns. Does it answer your question any better?</p> <p>Another possible tactic would be, to couple message and callback, but having the Callback be a <code>Func&lt;Response, bool&gt;</code> and the dispatcher thread checks if the result returned from the Func is true, then this callback is <em>disposed</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload