rafallopatka / ToastNotifications

Toast notifications for WPF allows you to create and display rich notifications in WPF applications. It's highly configurable with set of built-in options like positions, behaviours, themes and many others. It's extendable, it gives you possibility to create custom and interactive notifications in simply manner.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Black dialog is appearing when i use the notifications

udaykolluru opened this issue · comments

Hi ,

I used toast notifications in my application ,where i can see the black dialog appears on the screen when we use notifications.This happens when i run a long executing method.

Note : The Black Dialog appear in release mode of my application,but not in debug mode . But I can see the Exception in debug code from the following code which is in

2018-11-14 10:01:30.411 0001 Error DbTracer 'System.InvalidOperationException: This Visual is not connected to a PresentationSource.
at System.Windows.Media.Visual.PointToScreen(Point point)
at ToastNotifications.Position.ControlPositionProvider.GetPosition(Double actualPopupWidth, Double actualPopupHeight)
at ToastNotifications.Display.NotificationsDisplaySupervisor.UpdateWindowPosition()
at ToastNotifications.Display.NotificationsDisplaySupervisor.PositionProviderOnUpdatePositionRequested(Object sender, EventArgs eventArgs)
at ToastNotifications.Position.ControlPositionProvider.RequestUpdatePosition()
at ToastNotifications.Position.ControlPositionProvider.ParentWindowOnLocationChanged(Object sender, EventArgs eventArgs)

I don't know why black dialog is not appearing without notifications . and it works fine.

Any help Regarding this can be appreciated.

Thanks in Advance

any info here ...

Could you provide some code to reproduce that behaviour?

Hi,
I came across the same issue recently and I also managed to reproduce it on a basic demo app.
It happenes when the main app thread is blocked and the transparent window container is not able to draw itself.
Any help with this one would be appreciated.

I have same issue. Reproducing is not easy, but it happen when main thread is blocked for longer time (1-5 seconds), for example when main thread calls something like wcf service, and some notifications are in progress. Then black rectangle can be shown until thread unblocks. It probably happen more often on slower PC. Question is if it can be solved.

Actually blocking main thread is enough, I can provide you with a sample app. However I'm afraid that this use case scenario is not recommended and our request may be rejected :)

I know that the main thread should not be blocked and some functionality should be called in another thread. But the world is not ideal and when you inherit a large application that is not written ideally these problems arise. Maybe, that black rectangle can be solved - for example by transparent background.

Hi, as I remember this window (hosting notifications) is already transparent. I think the window turns black because system/wpf cannot repaint it's surface because ui thread is blocked, there is only one ui thread in wpf so we can't do anything while this thread is busy. Maybe there is some "hacky" way of hiding window in WinAPI to use when app freezes, (but still UI in WinAPI use message loop - so it's "single thread" by default" ).

I think things like that can be usefull, but it's not a normal use case, much better for your app would be improve places in code which freezes ui. You can use standard c# tasks and dispatcher, or use ReactiveExtensions, which gives you many good solutions for asynchronous programming. With them it's quite easy to switch operations between threads.
Here is an example of thread switching

https://github.com/rafallopatka/Rx.NET-Presentation/blob/master/ReactiveExamples/09_ObserveOn/Program.cs

In c# there is something like DispatcherScheduler - which can be used for interactions with ui, and we can easily use Rx with tasks, callbacks, events, and many other sources of asynchronous data/operations.

much better for your app would be improve places in code which freezes ui.

Well yes, but in case of inherited apps it is not that easy. I tried to improve notifications container window, but there was not much I could do. The only hack that worked for me was forcing dispatcher to repaint the app inside locking operation:

Dispatcher.Invoke(((Action)(() => {; })), DispatcherPriority.Render);

Preview of what we're facing:

obraz

Window is transparent and during a 'freeze' system probably tries to determine what is behind it and gets zero value which is black. When I changed window background to a solid color it stayed the same as I defined. Another try was to use semi transparent gradient from solid to transparent. In that case it also tends to fade in black instead of transparent.

Maybe we could at least hide container window if there are no messages displayed?

Yes, have same black rectangle with difference it does not contains any displayed message - just black rectangle.

Doesn't help something like this?

https://stackoverflow.com/questions/3758838/determine-what-is-blocking-ui-thread

https://social.msdn.microsoft.com/Forums/vstudio/en-US/693fbedb-efa6-413e-ab66-530c6961d3fb/how-to-wait-for-the-wpf-render-thread-to-quotcatch-upquot?forum=wpf


In our case, have large database application which was created from older PowerBuilder application by translation, with many thousands nested, hierarchical sql commands (which can block main thread without possibility send some "do events" events) - this cannot be changed because of black rectangle in notifier.

Maybe we could at least hide container window if there are no messages displayed?

I see that idea has already been picked but is waiting for approval.

6ae52e9

@rafallopatka please accept and release new version :)

Hi thanks for pull request, new version released 2.5.1