Conversation
Introduces `WaitForOpened` and `WaitForClosed` methods on `DialogHost` to enable asynchronous waiting for the completion of the dialog's visual state transitions. This provides more precise control for executing logic precisely after the dialog has fully opened or closed, rather than just when events are dispatched. Updates the `DialogSession` to expose the parent `DialogHost` instance, facilitating access to these new awaitable methods.
nicolaihenriksen
left a comment
There was a problem hiding this comment.
Only some minor comments. Looks good to me though.
| currentState = _visualStateGroup.CurrentState.Name; | ||
| if (currentState == state) | ||
| { | ||
| _visualStateGroup.CurrentStateChanged -= stateChanged; | ||
|
|
||
| return Task.CompletedTask; | ||
| } |
There was a problem hiding this comment.
Don't you already have this guard in line 17-18? Is there a scenario where the current state can change between line 18 and here?
| } | ||
|
|
||
| public Task WaitForOpened(CancellationToken cancellationToken = default) | ||
| => _visualStateMonitor?.WaitForState(OpenStateName, cancellationToken) |
There was a problem hiding this comment.
Regarding whether cancellationToken should be required: How about setting a reasonable self-cancelling token (say 5 seconds) if one is not supplied by the caller? I guess what you're trying to avoid by making it mandatory is the infinite hang waiting for a state change that never occurs? A reasonable default token would do that too I guess.
My assumption here is that the caller would only call these methods right before opening/closing the DialogHost and therefore the timeout should just be slightly longer than the duration of the animation. I hope my assumption is correct.
Potential Fix for #4017
Introduces
WaitForOpenedandWaitForClosedmethods onDialogHostto enable asynchronous waiting for the completion of the dialog's visual state transitions. This provides more precise control for executing logic precisely after the dialog has fully opened or closed, rather than just when events are dispatched.Outstanding items:
Updates the
DialogSessionto expose the parentDialogHostinstance, facilitating access to these new awaitable methods.