title: Singleton events
body: <p>I am refactoring some old code, where I have a lot of static events like this</p>
  
  <pre><code>public static event Action Updated;
  public static void OnUpdated()
  {
      if (Updated != null)
          Updated();
  }
  </code></pre>
  
  <p>I found out what using <a href="http://csharpindepth.com/articles/general/singleton.aspx#lazy" rel="nofollow noreferrer">lazy singletons</a> is often better than using static classes:</p>
  
  <ul>
  <li>no memory is consumed until first <code>Instance</code> call;</li>
  <li>private serialization/deserialization.</li>
  </ul>
  
  <p>So that I refactor those to singletons and now I have Code Analysis complains.</p>
  
  <p>Such events clearly offend <a href="https://msdn.microsoft.com/en-us/library/ms182133.aspx" rel="nofollow noreferrer">CS1009</a> but I have some doubts:</p>
  
  <ul>
  <li><p>for static events <code>sender</code> doesn't makes sense, why and in what scenario would singleton <code>sender</code> be of any use? I can only think about deserialization, but it's an internal class implementation (moreover class is sealed), so I can take care to not use events and if I need one, I can create private event.</p></li>
  <li><p>creating <code>e</code> (deriving from <code>EventArgs</code>) is unnecessary complication to simply pass parameters, the biggest part I hate is to move it into namespace level, the only thing which <code>EventArgs</code> adds (could be useful sometimes) is <code>Empty</code> and then you have dozens of classes <code>...EventArgs</code>. I could think what sometimes you need <a href="https://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx" rel="nofollow noreferrer">Cancel</a> or <a href="https://msdn.microsoft.com/en-us/library/system.componentmodel.handledeventargs.handled.aspx" rel="nofollow noreferrer">Handled</a> mechanics, but it was neverd needed for me.</p></li>
  </ul>
  
  <p>When using event does everybody expect <code>(object sender, SomeEventArgs args)</code> and this is the only reason?</p>
  
  <p>To summarize, here is my <em>main</em> question (but I would appreciate clarifying other questions as well): CS1009 and singletons, should I fix events or simply suppress the message?</p>
  
  <p>P.S.: related subjects: <a href="https://stackoverflow.com/a/2789642/1997232">this</a>, <a href="https://stackoverflow.com/q/4462050/1997232">this</a> and <a href="https://stackoverflow.com/q/16959822/1997232">this</a>.</p>
  
  <hr>
  
  <p>I found <a href="https://stackoverflow.com/q/17856823/1997232">this</a> question. According to <a href="https://msdn.microsoft.com/en-us/library/vstudio/ms229011.aspx" rel="nofollow noreferrer">event design guidelines</a> I have to use <code>Event&lt;T&gt;</code> (disregards to <a href="https://stackoverflow.com/q/6048386/1997232">this</a> question), where <code>T</code> is based on <code>EventArgs</code> class.</p>
  
  <p>Regarding <code>sender</code> in static events:</p>
  
  <blockquote>
    <p>On static events, the <code>sender</code> parameter should be null.</p>
  </blockquote>
  
  <p>This is a  <em>design guideline</em>, which may not looks pretty <strong>to me</strong>, but will be very welcomed by anybody else (who is reading/maintaining my code).</p>
  
  <p>It breaks both <a href="https://en.wikipedia.org/wiki/KISS_principle" rel="nofollow noreferrer">KISS</a> and <a href="https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it" rel="nofollow noreferrer">YAGNI</a> principles as for me. And the more I think about it, the less and less I am sure of what to do.</p>