In the class header I've declared
private:
concurrency::reader_writer_lock myLock;
And changed the implementation to:
storyboard->Completed += ref new EventHandler<Object^>
([this,birthImage](Object^ sender, Object^ e) {
unsigned int index;
myLock.lock();
if (mainGrid->Children->IndexOf (myImage, &index))
{
mainGrid->Children->RemoveAt (index);
}
myLock.unlock();
});
Notice the declaration of unsigned int index
as a local variable to the lambda
function.