Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it necessary to call EndInvoke in the callback from an EventHandler.BeginInvoke (C# .Net 3.5)
    primarykey
    data
    text
    <p>I'm setting up a WCF client and server scenario that needs to be reliable and scalable and as part of that I'm trying to make it multithreaded. Admittedly I don't have extensive multithreading experience.</p> <p>On the client, the callback from the server (in this case "OnMessage") fires a client-side event that should be passed off in the background. I have the client's CallbackBehavior ConcurrencyMode set to Single (at least, for now). So in order to do a reply to the callback, rather than calling the handler as normal (either handler(sender, eventargs, or handler.Invoke...) I'm calling handler.BeginInvoke.</p> <p>Everything works fine, but in the callback I'm wondering if I need to explicitly call EndInvoke or if I can basically do nothing (here's my lack of multithreading experience showing).</p> <pre><code>public void OnMessage(Message message) { EventHandler&lt;MessageEventArgs&gt; handler = OnServerMessage; if (handler != null) handler.BeginInvoke(this, new MessageEventArgs(message), CompleteHandler, handler); } public void CompleteHandler(IAsyncResult result) { ((EventHandler&lt;MessageEventArgs&gt;)result.AsyncState).EndInvoke(result); } </code></pre> <p>Can I replace CompleteHandler with a direct reference to handler.EndInvoke, or an empty method, or perhaps is there something more I should be doing?</p> <p>Also, at the moment, the event subscriber blocks waiting on user input from the console. When the application is complete, it would either block waiting on the database, or be asynchronous bottom-to-top (so this may not be necessary, but I'd still like to know).</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. 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