When developing TfsSnarl and later a weather watcher for Snarl I came to the conclusion that writing tiny .NET applications that should stay in memory and perform tiny dedicated tasks is not such a seldom thing to do. However what keeps me from doing lots of those things is that the system tray get's filled with more stuff you do not want to have there with a dedicated item.
nTray is a tool for just that. It uses MEF to discover modules that perform these background tasks. In addition to hosting these modules it can provide a UI entry point for settings and custom actions. There is no real configuration to link in new modules. You can just drop your assemblies in a folder, implement a simple interface and you are good to go.
I've included a tiny (but rather useless Module) to show how it works. Let's take a look.
- Fixed bug with click event in context menu.
- Additionally scan one folder below module directory folders.
- Added error message when a folder does not exist.
Configuring Modules Directories
You can configure where to scan for modules. By default nTray will search beneath it's Modules folder. If you intend to add additional folders (e.g. for modules that are bigger and require more files to run), you can add additional folders to the configuration nTray.exe.config:
<setting name="SearchDirectories" serializeAs="Xml">
In addition to the folder itself, nTray will folder subfolders of a module folder. This allows to drop a module into a subfolder of the standard module folder without the need to extend the configuration.
Implementing a Module
Modules need to implement the Schommer.Projects.nTray.Modules.INTrayModule interface which is located in the Schommer.Projects.nTray.Interfaces.dll assembly.
public interface INTrayModule
To make a module available to MEF you have to export it using an attribute:
returns the name of the module as it will show up in your system tray.
- Image (may be null)
is an image to show in the tray menu besides the name.
- DropDown (may be null)
is a ToolStrip menu that allows to embed custom actions.
is called when nTray launches. If the method returns False, the module is assumed to be inactive. In that case the image will be shown as disabled.
is called when the application is exiting.
When launching nTray will instantiate a system tray icon and embed an entry for each module in the context menu. As you can see the clock demo module provides a sub menu.
There is really not more to know. Perhaps you create your own modules as I will surely do in the next days. I'm really interested whether you find this tool useful.
nTray-0.2.zip (101,49 kb)
nTray-0.1-DemoModule-src.zip (26,83 kb)