Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Due to the fact, that Benjol doesn't know, why he places the Action into a MethodInvoker and broccliman meant to use it as an Extension Function, here is the clean up code:</p> <pre><code>static class SafeInvoker { //Utility to avoid boiler-plate InvokeRequired code //Usage: myCtrl.SafeInvoke(() =&gt; myCtrl.Enabled = false); public static void SafeInvoke(this Control ctrl, Action cmd) { if (ctrl.InvokeRequired) ctrl.BeginInvoke(cmd); else cmd(); } //Replaces OnMyEventRaised boiler-plate code //Usage: this.RaiseEvent(myEventRaised); public static void RaiseEvent(this object sender, EventHandler evnt) { var temp = evnt; if (temp != null) temp(sender, EventArgs.Empty); } } </code></pre> <p>Just a last note: <code>MethodInvoker</code> and <code>Action</code> are both just delegates having the exact same structure. Due to this case both are replaceable by each other. The root of this naming clash comes from legacy. At the beginning (.Net 2.0) there was just <code>MethodInvoker</code> and <code>Action(T)</code>. But due to the fact, that everyone who used <code>Action(T)</code> whishes to have a <code>Action</code> and found it very unnatural to take <code>MethodInvoker</code>. So in .Net 3.5 the <code>Action</code>, <code>Action(T1, T2, T3, T4)</code> and all the <code>Func</code> delegates where added too, but MethodInvoker could not be removed anymore without making any breaking changes.</p> <h3>Additional:</h3> <p>If you are able to use .Net 3.5 the above code is fine, but if you're pinned to .Net 2.0 you can use it as normal function as before and replace <code>Action</code> by <code>MethodInvoker</code>.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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