title: C# Excel: delegate set to capture cell selection behaves intermittently
body: <p>I have created an interface to define a RangeSelectionTarget as follows:</p>
  
  <pre><code>public interface IRangeSelectionTarget
  {
      void OnRangeSelection(Excel.Range target);
  }
  </code></pre>
  
  <p>In another class (ExcelController, encapsulating excel interop behavior), I have a method to pipe the worksheet range selections (using the mouse to select cells) to the target:</p>
  
  <pre><code>    public void SelectCaptureOn(IRangeSelectionTarget target)
      {
          _selectionCallback += new SelectionCallback(target.OnRangeSelection);
          _selectionCallback += new SelectionCallback(SelectionCallback2);
  
          int limit = _workbook.Worksheets.Count;
  
          for (int i = 1; i &lt;= limit; i++)
          {
              Excel.Worksheet worksheet = _workbook.Worksheets.get_Item(i);
              string worksheetName = worksheet.Name;
              worksheet.SelectionChange
                  += new Excel.DocEvents_SelectionChangeEventHandler(OnXlSelectionCallback);
          }
      }
  </code></pre>
  
  <p>The target, a form, implements OnRangeSelection() as follows in order to display the cell addresses:</p>
  
  <pre><code>    public void OnRangeSelection(Excel.Range target)
      {
          if (this.InvokeRequired)
          {
              RangeSelectionDelegate rsDel = new RangeSelectionDelegate(OnRangeSelection);
              this.Invoke(rsDel, new object[] { target });
          }
          else
          {
              txtRange.Text = target.AddressLocal;
              txtRange.Tag = target;
          }
      }
  </code></pre>
  
  <p>This works great, except when it doesn't.  After calling SelectCaptureOn(), OnRangeSelection() starts getting called on the IRangeSelectionTarget, that then displays the addresses of the selected cells.  OnRangeSelection() checks for InvokeRequired in order to avoid threading issues....or so I hope. </p>
  
  <p>The problem is that after a few successful selection displays, the behavior stops completely dead.  </p>
  
  <p>Any ideas why, or where to start investigating?</p>
  
  <p>Thanks!</p>