Please Help. I put this construction in any method to main ViewModel
Thread thread = new Thread(() =>
{
_visualizerService.ShowDialog(new PurchaseWindowViewModel());
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
And i have exception in PurchaseWindowViewModel.xaml.cs
An exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll but was not handled in user code. Additional information: Not access to object Freezable "Catel.Windows.Media.Effects.GrayscaleEffect"
through the threads, as it can not be frozen.
Creating a window on a separate thread is hardly ever required and only "required" in edge-case scenarios. Please update your question why you want to use a window on a non-ui thread if the answer below does not solve your issue.
I recommend that you use this code instead:
await _visualizerService.ShowDialogAsync<PurchaseWindowViewModel>();
or non async:
_visualizerService.ShowDialog<PurchaseWindowViewModel>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.