tags:

views:

683

answers:

4

I'm writing a WPF application which will monitor a feed. When there are new items determined from the feed I want to spawn off small windows as a notification. If anyone's familiar with Growl on OS X, that kind of what I'm trying to do. Also, I'll point out that this is my first WPF application (and the first time I've done something that's not a web app for a while!).

I was originally do code like this:

foreach(var feedNotification in newFeedNotifications) {
  var popupWindow = new PopupWindow() { ... };
  popupWindow.Show();
}

The problem is that the above is very CPU intensive, the the point where it's taking about 50% CPU usage. Also, I want to be able to track the position of the on-screen notifications so that if the next check finds more to show it knows where the last currently visible one is and the new ones are shown below the others.

How would I go about achieving this while ensuring that the computer running the application is not being brought to a hault?

Edit: I'm using the .NET 3.5 SP1 framework

+2  A: 

I'm not 100% on this, but I think it would be much more efficient to spawn a new instance of the window into a collection maintained by your main window (or an object there-in). Then you could create an event that could be subscribed to by the newly spawned window. Once the new windows are watching for updates from the main window or object, you could just fire the event on the main window and let your notification windows take care of the rest.

As far as the notification window tracking, you could allow the notification windows to be alerted via another event hookup that there is a new window to display, and pass it to them (or allow them to retrieve it from the main object.) You can place that window directly beneath the currently visible notification by tracking when the window receives focus. So, the last window that received focus is the one that was last viewed. Once you have the existing window, it's just a matter of creating the new one in the same location (or slightly offset) then calling the focus of the window that's on top.

An alternative to tracking the active window via the focus check would be to just go through the collection of window objects contained in your main window, since the collection would be in order of creation. Hope this helps.

Found this link a minute ago regarding popup controls that have some useful properties tied to them.

Dustin Hoffman
+1  A: 

Is it absolutely necessary to create a new window for each notification? While I haven't measured this, it could be that creating new WPF windows is a CPU intensive task. If that is the case, then there isn't much that you can do to change your code to use less CPU.

Would it be possible to just create one notification window, and it will contain a list of all of the new notifications? I realize that this isn't how Growl works, but this would provide the same information, just in a different way.

Andy
A: 

I'm not sure about CPU utilisation (and being dual core with good GPU's on all my machines I don't care about it much), but it looks like you're trying to do a "balloon popup", and the good project to re-use would be codeproject WPF NotifyIcon (This is what I use in my own RSS reader)

Sergey Aldoukhov
+1  A: 

Why not use the Windows version of Growl? (http://www.growlforwindows.com)

If that isn't possible, just create a single transparent window, whose contents is an ItemsControl; the ItemsControl source are your notifications

Paul Betts
I wasn't aware that existed, but what I'm trying to do is a POC on integrating a few systems which aren't meant to integrate. Using that would defeat the purpose of what I'm trying to do
Slace
I don't even know what that sentence means.
Paul Betts