I have two different projects and in one, I have a class that defines a custom event to fire under certain conditions:
  public delegate void ButtonHandler(object myObject,
                                           GuitarArgs myargs);
        public event ButtonHandler OnButtonPress;
... other stuff ...
  GuitarArgs myArgs = new GuitarArgs( guitarState );
                if(OnButtonPress!= null)
                     OnButtonPress(this, myArgs);
Then in another project I create an instance of this class and subscribe to this event:
Guitar.OnButtonPress += Guitar_OnButtonPress;
The event then fires properly, but it seems to be on a different thread, because when I try to access some UI elements, I get an error : The calling thread cannot access this object because a different thread owns it.
The code throwing the error is:
 void Guitar_OnButtonPress(object myObject, Guitar.GuitarArgs myargs)
        {
            GuitarCheck(myargs.State);
        }
        private void GuitarCheck(GuitarState getState)
        {
                if (getState.green) 
                {
                    VisualTreeHelper.HitTest(guitarCanvas, null,
                                             MyHitTestResult,
                                             new GeometryHitTestParameters(
                                                 new RectangleGeometry(new Rect(1, 411, 88, 78))));
                }
}
What can I do to make this run?
Thank you.
 
     
     
     
    