Hello!
I am trying to use a Window component as a dialog with awaiting the result of an action.
Until the user presses the confirm or cancel button, the calling code must wait for an action.
In a Dialog component (not a Window component) this is implemented as:
My implemetation for Window component (component have two buttons with OnClick="@Submit(true or false)"):
This works, but WaitForResult method is overloading processor.
PLEASE help me with correct impementation...
I am trying to use a Window component as a dialog with awaiting the result of an action.
Until the user presses the confirm or cancel button, the calling code must wait for an action.
In a Dialog component (not a Window component) this is implemented as:
var result = await dialog.Show().Result;
bool isVisible, dialogResult;
CancellationTokenSource tokenSource;
public async Task<bool> Show() {
isVisible = true;
await InvokeAsync(StateHasChanged);
return await Task.Run(WaitForResult); }
// Waiting for action
private async Task<bool> WaitForResult() {
tokenSource = new();
while (!tokenSource.Token.IsCancellationRequested) ;
isVisible = false;
await InvokeAsync(StateHasChanged);
return dialogResult; }
private async void Submit(bool result) {
dialogResult = result;
tokenSource.Cancel(); }
This works, but WaitForResult method is overloading processor.
PLEASE help me with correct impementation...