MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
14.91k stars 3.4k forks source link

Dialogs stop rendering sometimes #2306

Closed andreyea closed 1 year ago

andreyea commented 3 years ago

I use Material in Excel addin dialogs. I all works fine, but sometimes the dialog may become unresponsive. If I close it and open it again, the whole thing is just blank and to make it work I need to restart the application. I cannot figure out what may cause this and I see no any errors during debugging. I just wonder if anyone else experienced this issue.

Thanks.

Keboo commented 3 years ago

I have occasionally seen issues like this where there are deadlocks in the code. Typically caused by using the async DialogHost methods and combining them with calls to Task.Result or similar. Any chance there is something like that in your implementation?

andreyea commented 3 years ago

I do have async code inside these dialogs.

The dialogs are just window classes which are displayed using ShowDialog methods.

Is there any specific way to display a dialog which uses MaterialDesign?

andreyea commented 3 years ago

Hi @Keboo ,

I have read more about what are DialogHosts and no, I don't use them at all.

I only have windows which are called from Excel ribbon and I just use elements from Material XAML to style the form.

I notice, this may happen after Excel is being idle for some time and then when I open one of the windows elements are not responsive, dragging the window becomes slow. When close and reopen it again, the whole window is just blank.

Is there a way to debug this?

Thanks

andreyea commented 3 years ago

Another thing I just noticed is when this happens, Excel RAM consumption jumps from a few hundred mb to tens of gb in a matter of seconds and goes up and down. Once I close this blank window, the memory stays down.

andreyea commented 3 years ago

I tried to enable Software Rendering for each window that uses Material elements in Window Loaded event. For now, I cannot replicate this issue any more, but will keep an eye on it.

Keboo commented 3 years ago

A couple of thoughts. Typically the behavior you are describing is caused because the UI thread is unable to process events. This either occurs because it is blocked/deadlocked or when it gets caught in an infinite loop (or long CPU load) on the UI thread. Being an Excel add-in certainly makes the problem much more difficult to debug. Though I am not too familiar with building these add-ins, I would expect that Excel isolates each extension to keep them from interfering with the main application, which is why are you still able to close the window. A few thoughts and ideas that might help.

  1. You commented on the RAM usage, but what does the CPU do during this time? Given that we are either looking for a deadlock or an infinite loop it is often helpful to know which case to be looking for. If the CPU usage for the process stays low/idle you are likely looking for a deadlock; otherwise a long running process or infinite loop.
  2. Is the ShowDialog() calls on the window strictly necessary or could you use Show()? ShowDialog is a blocking call, and since the problem could be related to the UI thread being blocked and that is a block UI call, it could be related to that.
  3. Are you able to launch and attach a debugger to it? If this is possible, it would be good to pause the process in the debugger and investigate the call stack of each of the threads. This might help shed some light on what is happening.
  4. This is a bit of a long shot, but are you able to attach snoop to the window when the problem occurs? Often if the UI thread is hung snoop wont be able to, but the fact you are able to close the window makes me curious if this would work (being unfamiliar with the isolation in Office Add-Ins I am not really sure what will happen).
andreyea commented 3 years ago
  1. CPU and GPU use up to 30% while the window is active
  2. All dialogs are being started on a new thread, so the users can still interact with Excel
  3. I can attach debugger to Excel process, but not sure what to look for and where to start. There are no errors or messages thrown while debugging.
  4. I will try snoop.
github-actions[bot] commented 1 year ago

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.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 14 days with no activity.