-
Notifications
You must be signed in to change notification settings - Fork 3.5k
dialog host task was canceled issue #3824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
even this throw exception var rrr= DialogHost.GetDialogSession (_mainWindow.GetDialogIdentifier()); |
this is stack trace Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in mscorlib.dll |
@AmeerMansour I'm afraid I don't quite understand your problem.
Which would look something like this: public partial class MyVM : ObservableObject
{
public const string DIALOG_IDENTIFIER = "RootDialog";
[RelayCommand]
private async Task ShowDialogs()
{
// Intentionally not await this call so the 2nd dialog is shown automatically after 2 seconds
DialogHost.Show(CreateTextBlock("content 1"), DIALOG_IDENTIFIER);
await Task.Delay(2000);
DialogHost.Close(DIALOG_IDENTIFIER);
await DialogHost.Show(CreateTextBlock("content 2"), DIALOG_IDENTIFIER);
}
private static TextBlock CreateTextBlock(string text) =>
new()
{
Text = text,
Margin = new Thickness(16)
};
} However this works fine for me. Please provide more clear reproduction steps, or even better, a sample repo showcasing this bug. |
It is quite complex to replicate the system. I will try to be clearer on my scenario.
|
@AmeerMansour I have tried to replicate the scenario you describe, but I am not seeing the error, so I am probably doing something wrong compared to you. Perhaps you can elaborate a bit more. Let me explain what I have done: In the Main demo app of MDIX I have added a button on the start page. I have configured the private IHost? _host;
private void OpenDialogHostWindowButton_Click(object sender, RoutedEventArgs e)
{
if (_host is { } oldHost)
{
oldHost.Dispose();
}
_host = CreateHostBuilder([]).Build();
var launcher = _host.Services.GetRequiredService<DialogHostWindowLauncher>();
launcher.LaunchDialogHostWindow(_host);
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddTransient<DialogHostWindowLauncher>(); // Also tried AddSingleton(); still works...
}); This basically just creates a generic host where it adds a single service to the service collection, namely a internal class DialogHostWindowLauncher : IDisposable
{
private DialogHostWindow? _window;
public void LaunchDialogHostWindow(IHost host)
{
Thread newWindowThread = new(() =>
{
_window = new DialogHostWindow();
_window.Closing += (_, __) => host.Dispose();
_window.Show();
System.Windows.Threading.Dispatcher.Run();
});
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
newWindowThread.Start();
}
public void Dispose()
{
if (_window is { } window)
{
window.Dispatcher.BeginInvoke(() => window.Close());
}
}
} The dialog that it creates is just a simple Window which has <Window x:Class="MaterialDesignDemo.DialogHostWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:MaterialDesignDemo"
mc:Ignorable="d"
Style="{StaticResource MaterialDesignWindow}"
WindowStartupLocation="CenterScreen"
Title="DialogHostWindow" Height="450" Width="800">
<materialDesign:DialogHost ApplyBlurBackground="True" CloseOnClickAway="True">
<materialDesign:DialogHost.DialogContent>
<StackPanel Margin="50">
<TextBlock Text="This is some text in a DialogHost" />
<Button VerticalAlignment="Bottom" HorizontalAlignment="Center" Content="Close Dialog" Margin="10" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" />
</StackPanel>
</materialDesign:DialogHost.DialogContent>
<Grid>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Center" Content="Show Dialog" Margin="10" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" />
</Grid>
</materialDesign:DialogHost>
</Window> With this setup, I can continuously open the window in its own UI thread, click the button and thus show the dialog in the newly opened window. Works both with a transient launcher as well as a singleton launcher. My guess is that your code for creating the host and/or creating the UI thread is somewhat different than this; could you help me better understand how your code looks? Thanks. |
This issue is marked stale because it has been open 30 days with no activity. Remove stale label or update the issue, otherwise it will be closed in 14 days. |
Bug explanation
I am using material design in developing addins for 3d softaware so I am using host the first time i uses dialog it shows correctly but when i end the host and start new one, it throw this exception !
how to fix this error ?
Version
5.2.1
The text was updated successfully, but these errors were encountered: