== Why is this an issue? include::../description.adoc[] === Noncompliant code example BeginInvoke without callback [source,csharp] ---- public delegate string AsyncMethodCaller(); public static void Main() { AsyncExample asyncExample = new AsyncExample(); AsyncMethodCaller caller = new AsyncMethodCaller(asyncExample.MyMethod); // Initiate the asynchronous call. IAsyncResult result = caller.BeginInvoke(null, null); // Noncompliant - not paired with EndInvoke } ---- BeginInvoke with callback [source,csharp] ---- public delegate string AsyncMethodCaller(); public static void Main() { AsyncExample asyncExample = new AsyncExample(); AsyncMethodCaller caller = new AsyncMethodCaller(asyncExample.MyMethod); IAsyncResult result = caller.BeginInvoke( new AsyncCallback((IAsyncResult ar) => {}), null); // Noncompliant - not paired with EndInvoke } ---- === Compliant solution BeginInvoke without callback [source,csharp] ---- public delegate string AsyncMethodCaller(); public static void Main() { AsyncExample asyncExample = new AsyncExample(); AsyncMethodCaller caller = new AsyncMethodCaller(asyncExample.MyMethod); IAsyncResult result = caller.BeginInvoke(null, null); string returnValue = caller.EndInvoke(result); } ---- BeginInvoke with callback [source,csharp] ---- public delegate string AsyncMethodCaller(); public static void Main() { AsyncExample asyncExample = new AsyncExample(); AsyncMethodCaller caller = new AsyncMethodCaller(asyncExample.MyMethod); IAsyncResult result = caller.BeginInvoke( new AsyncCallback((IAsyncResult ar) => { // Call EndInvoke to retrieve the results. string returnValue = caller.EndInvoke(ar); }), null); } ---- include::../see.adoc[] ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) include::../message.adoc[] include::../highlighting.adoc[] ''' == Comments And Links (visible only on this page) include::../comments-and-links.adoc[] endif::env-github,rspecator-view[]