Reputation: 8762
Is there a way to assure the second statement executes after the first one?
DispatcherObjectInvoker.Invoke(_layouts,
() =>
_layouts.RaiseEvent(new LayoutEventArgs(
MainScreen.ChangedLayoutEvent,
this)));
DispatcherObjectInvoker.Invoke(_layouts, Grid.Refresh);
I'm accessing an Grid that is touched in the first statement. The refresh of the grid is working in about 80% of the cases only. I obviously have a race condition here.
Upvotes: 0
Views: 77
Reputation: 5574
Not sure what a DispatcherObjectInvoker
is, but I will assume it's a wrapper for Dispatcher
or something.
If it is, if you call Invoke()
, it is a blocking call. So your second call is guaranteed to be after your first call.
However, if your intent is to have those be asynchronous calls, you should use BeginInvoke
. The DispatcherPriority
parameter helps ensure that calls made to the same priority level are in the same order. So, if _layouts
refers to the DispatcherPriority.Loaded
priority (or any other priority), the calls are guaranteed to be in the same order.
Check the MSDN documentation.
Upvotes: 0
Reputation: 1499810
Why not make them both part of the same action?
DispatcherObjectInvoker.Invoke(_layouts, () =>
{
_layouts.RaiseEvent(new LayoutEventArgs(MainScreen.ChangedLayoutEvent,
this));
Grid.Refresh();
});
Upvotes: 3