title: Reasons that Control.BeginInvoke would not execute a delegate?
body: <h2>Overview</h2>
  
  <p>Are there explanations for Control.BeginInvoke() to not execute a delegate that it is passed?</p>
  
  <h2>Code Sample</h2>
  
  <p>We have adopted the following pattern in our Winforms applications to safely execute UI releated work on the UI thread:</p>
  
  <pre><code>private Control hiddenControl = new Control();
  
  private void uiMethod()
  {
    MethodInvoker uiDelegate = new MethodInvoker(delegate()
    {
      Logging.writeLine("Start of uiDelegate");
      //ui releated operations
      childDialog = new ChildDialog();
      childDialow.show();
      Logging.writeLine("End of uiDelegate");
    });
  
    if (hiddenControl.InvokeRequired)
    {
      Logging.writeLine("Start of InvokeRequired block");
      hiddenControl.BeginInvoke(uiDelegate);
      Logging.writeLine("End of InvokeRequired block");
    }
    else
    {
      uiDelegate();
    }
  }
  </code></pre>
  
  <p>Here, we create a control "hiddenControl" explicitly for the purpose of running delegates on the UI Thread.  We never call endInvoke because it's apparently <a href="https://stackoverflow.com/questions/532722/is-endinvoke-optional-sort-of-optional-or-definitely-not-optional">not required</a> for Control.BeginInvoke and we never need to return a value because our methods just manipulate UI, anyway.</p>
  
  <p>While extremely verbose, this pattern seems to be a <a href="http://www.codeproject.com/Articles/10311/What-s-up-with-BeginInvoke" rel="nofollow noreferrer">relatively</a> <a href="https://stackoverflow.com/questions/229554/whats-the-difference-between-invoke-and-begininvoke">well</a> <a href="https://stackoverflow.com/questions/532722/is-endinvoke-optional-sort-of-optional-or-definitely-not-optional">accepted</a> <a href="https://stackoverflow.com/questions/714666/is-it-appropriate-to-extend-control-to-provide-consistently-safe-invoke-begininv">solution</a>.  There is, however, some <a href="https://stackoverflow.com/questions/6270514/control-begininvoke-fails-to-call-the-delegate">evidence</a> that even this pattern may not work well in all situations.</p>
  
  <h2>Observations</h2>
  
  <p>I'm not ruling out an application error and blaming WinForms.  After all, <a href="http://pragprog.com/the-pragmatic-programmer/extracts/tips" rel="nofollow noreferrer">select probably isn't broken</a>.  I am however at a loss to explain why a delegate may seemingly not run at all.  </p>
  
  <p>In our case, we sometimes observe that the "Start of uiDelegate" log message never executes in certain threading scenarios, even though the "Start of InvokeReqiured block" and "End of InvokeRequired block" execute successfully.  </p>
  
  <p>It's been very hard to replicate this behavior because our application is delivered as a DLL; our customers run it in their own applications.  Therefore, we can not make any guarantees how or in which thread these methods may be called.</p>
  
  <p>We ruled out UI thread starvation because it is observed that the UI does not lock down.  Presumably, if the UI is being updated, then the message pump is operational and available for pulling messages from the message queue and executing their delegates.</p>
  
  <h2>Summary</h2>
  
  <p>Given this information, is there anything that we can try to make these calls more bullet-proof?  As previously mentioned, we have relatively little control over other threads in a given application, and do not control which context these methods are invoked.</p>
  
  <p>What else can affect how delegates successfully passed to Control.BeginInvoke() execute or not?</p>