punker76 / MahApps.Metro.SimpleChildWindow

A simple child window for MahApps.Metro
MIT License
374 stars 55 forks source link

Trying to call mahapps ShowProgressAsync() from nested Childwindow causes exception #95

Closed Martin-Pucalka closed 4 years ago

Martin-Pucalka commented 5 years ago

When I try to call ShowProgressAsync() from one opened window (Window1), everything works fine. When I open another window (Window2) from Window1 and then try to call ShowProgressAsync() from Window2, then I get exception:

System.InvalidOperationException HResult=0x80131509 Zpráva=Sequence contains more than one element Zdroj=System.Core StackTrace: at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at MahApps.Metro.Controls.Dialogs.DialogManager.AddDialog(MetroWindow window, BaseMetroDialog dialog) at MahApps.Metro.Controls.Dialogs.DialogManager.SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog) at MahApps.Metro.Controls.Dialogs.DialogManager.<>c__DisplayClass3_0.<ShowProgressAsync>b__1() at System.Windows.Threading.DispatcherOperation1.InvokeDelegateCore() at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout) at System.Windows.Threading.Dispatcher.Invoke[TResult](Func1 callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout) at System.Windows.Threading.Dispatcher.Invoke[TResult](Func1 callback) at System.Threading.Tasks.ContinuationResultTaskFromTask1.InnerInvoke() at System.Threading.Tasks.Task.Execute() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at MahApps.Metro.SimpleChildWindow.Demo.TestChildWindow2.d__2.MoveNext() in C:\Users\Pucalka\source\repos\MahApps.Metro.SimpleChildWindow\src\MahApps.Metro.SimpleChildWindow.Demo\TestChildWindow2.xaml.cs:line 38 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at MahApps.Metro.SimpleChildWindow.Demo.App.Main()

There is examples of this behaviour in the attachement. Is it bug or I can't do that? In both cases I call: await _mainWindow.ShowProgressAsync("Progress", "Please wait...");

May be realted to: https://github.com/punker76/MahApps.Metro.SimpleChildWindow/issues/90

Exception.zip Ok.zip

punker76 commented 4 years ago

Duplicate of #90