title: drawing an ellipse in wpf from within a secondary thread
body: <p>I am writing a wpf application in which balls are bouncing independently on a canvas, each ball in a different thread. Each time the user clicks on the canvas a new thread is added to the threadpool and an ellipse representing the ball is created. In order to add the ellipse and draw it I use Dispatcher.Invoke. However, the command myCanvas.Children.Add(el); called from within the code surrounded by Invoke causes the application to crash the moment the Invoke block ends, by entering break mode. 
  Obviously, this is not the way to achieve my goal, so how can I do it? </p>
  
  <pre><code>        Dispatcher.Invoke(new Action(() =&gt;
          {
              Ellipse el = new Ellipse();
              el.Fill = color1;
              el.Margin = new Thickness(10);
              el.Height = 40;
              el.Width = 40;
              balls.Add(ballsCounter, el);
              Canvas.SetTop(el, p.Y - 2 * el.Height / 3);
              Canvas.SetLeft(el, p.X - 2 * el.Width / 3);
              myCanvas.Children.Add(el);
              tbNumBalls.Text = ballsCounter.ToString();
          }));
  </code></pre>