System tray application to notify every 2 hours
I am trying to make a system tray application that loads on startup and pops a balloon text every 2 hours. If there is such an example its great.
I am looking to use.
WPF, Timers, Delegates, event开发者_Go百科s
I am not sure if these are enough or do I need something more.
Thanks in advance.
I think you will be fine with those. All you need is actually a NotifyIcon and a Timer. I've accomplished similar this way, except I wasn't using WPF (I rather used the 'classical' Window designer).
The simplest way to let your app start on startup would probably be to put it into Startup folder in the Start menu, there's actually no need to use the registry.
First of all here is what you need about starting your application on system startup : Lets say I have a checkBox and I want to start my application on windows startup if this checkBox is activated :
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
private void checkBox_autoStart_Checked(object sender, RoutedEventArgs e)
{
rkApp.SetValue("Your Application Name Here",Assembly.GetExecutingAssembly().Location);
}
and about the deactivation of that you do the follwoing :
private void checkBox_autoStart_Unchecked(object sender, RoutedEventArgs e)
{
rkApp.DeleteValue("Your Application Name Here", false);
}
p.s : Your application name will appear on the task manager the way you write it up there
And about using a notify Icon , well actually WPF doesn't support a ready made one so either you use the Windows Forms Notify Icon or you use the one mentioned in a nother answer from codeproject.com
if you wanted to use the one that already exists in windows forms , you have to add a reference to System.Windows.Forms in your project
A windows service may be the best thing for running in the background, but it may be tricky to get access to the GUI from a service (I don't think it's trivial).
For a WPF desktop app to do a tray notification, see this project with demo and source code: http://www.codeproject.com/KB/WPF/WPF_xaml_taskbar_window.aspx
To get the notification every 2 hours, you can use a DispatcherTimer: http://social.msdn.microsoft.com/Forums/en/wpf/thread/aaffea95-e735-492d-bd8a-2fdf7099a936
精彩评论