I am trying to display a menu element in my application as soon as a specific bluetooth message arrives. The messages are collected and interpreted through a timer method and if the correct message arrives, the element should be rendered visible. I keep getting an exception telling me that the object is owned by another thread and cannot be accessed.
// Shows a TangibleMenu element
private void Show(TangibleMenu TangibleMenuElement)
{
if (TangibleMenuElement.Shape.CheckAccess())
{
Debug.WriteLine("normal show");
TangibleMenuElement.Shape.Opacity = 1;
TangibleMenuElement.Shape.Visibility = System.Windows.Visibility.Visible;
this.ParentContainer.Activate(TangibleMenuElement.Shape);
}
else
{
Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
{
Debug.WriteLine("dispatcher show");
TangibleMenuElement.Shape.Opacity = 1; // EXCEPTION HERE
TangibleMenuElement.Shape.Visibility = System.Windows.Visibility.Visible;
this.ParentContainer.Activate(TangibleMenuElement.Shape);
}));
}
}
I thought that this exact issue could be solved by using the Dispatcher but in this case, it doesn't seem to work. TangibleMenuElement.Shape
is a ScatterViewItem from the Microsoft Surface SDK. Does anyone have any suggestions?
Dispatcher
thread the one that created theTangibleMenuElement
– sa_ddam213