title: Test Control Handle under Mobile .Net CF
body: <p>When my threads complete, I keep getting exceptions thrown.</p>
  
  <p>I can catch them, but I'd rather my code catch them first.</p>
  
  <p>This code could work for the full .Net Framework, but <code>IsHandleCreated</code> doesn't exist under the <em>Compact Framework</em>.</p>
  
  <p><strong>Question:</strong> <em>What should I use instead of <code>IsHandleCreated</code>?</em></p>
  
  <pre><code>Control _parent; // set when custom BackgroundWorker like class is created
  
  bool parentOk {
    get {
      if (_parent != null) {
        if (!_parent.IsDisposed) {
          return _parent.IsHandleCreated;
          // Should I instead "return (_parent.Handle != IntPtr.Zero);"?
        }
      }
      return false;
    }
  }
  
  public void ReportProgress(int step, object data) {
    lock (_thLock) {
      if (parentOk &amp;&amp; (ProgressChanged != null)) {
        MethodInvoker methInvoker = delegate { ProgressChanged(step, data); };
        try {
          _parent.BeginInvoke(methInvoker); // recently changed from below
          // _parent.Invoke(methInvoker); (old technique)
        } catch (ObjectDisposedException) { // added for BeginInvoke
        } catch (NullReferenceException err) {
          Global.LogError(_CODEFILE + "ReportProgress", err);
        } catch (InvalidOperationException err) {
          Global.LogError(_CODEFILE + "ReportProgress", err);
        }
      }
    }
  }
  </code></pre>