If I start a System.Threading.Timer
in a currently executing method, the method will continue to execute and return to the main method and the Timer.Tick
event will fire sometime in the immediate future (based on the timer's duration). For my purpose, I need something like a timer, but the duration would be calculated on the time it takes to finish executing the current method, i.e. the Tick executes directly after the current method returns.
Is there a way to 'schedule' a method to begin immediately after the current method executes before returning to the main method?
EDIT: Here's the issue I have that I am trying to work around.
A System.Windows.Controls.TreeviewItem
contains an event TreeviewItem.Collapsed
, which is internally invoked before layout, as we can see here in the OnIsExpandedChanged
method that item.UpdateVisualState()
is called after invoking the event. I therefore cannot use the updated layout to reposition my controls. IMO the event should be called OnCollapsing
or BeginCollapsed
.
I needed the collapsing to finish executing and then give me a chance to work with the new state.