Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a NotifyIcon with a Service

Status
Not open for further replies.

EDHills

Programmer
Jan 24, 2007
35
0
0
US
The questions
1) Has anyone successfully created a contextmenu on a NotifyIcon in a service? if so, could you give me some pointers? (I can get it to work not in a service)

2) If I'm supposed to create a tray icon app, which then communicates with the service, do you know of an example somewhere to aid me?



The whole story:
Ok, so I have a service which I'd like to be able to allow the user to configure settings and get status via a tray icon (NotifyIcon) I have the NotifyIcon working but I can't get the context menu to work. I wrote a quick test app with a NotifyIcon and a context menu and was able to add menuitems and have them appear when I right mouse click the icon, which, when it is a service, o context menu comes up. So, I've been digging, and reading.. and there's talk of solving the problem with ServiceController components or a number of ways. I wrote C++ code for years, but have been asked to work in VB .NET, so still relatively a rookie here, sorry.
Yes, I have read a lot and dug a lot.. just frustrated.. thanks in advance for reading this far

 
A service is designed to have no gui, so you can't have an notifyicon. You are right with the separate app idea.

The best way is to build a tcpclient(notifyapp) and listener(service) to send each other messages.

The funny thing is, i have just created an app+service combo like this, in the last week.

To prevent your app or service from locking up the computer, you'll need to use threading. I'll try and make an example after work...
 
Damn, thanks for reading my thread..
I'll look into it in the am.
 
Re-thinking about this,

You only need the notify app for making settings changes???

If so, you could create the notify app to change a settings file (xml,ini), and put a FileSystemWatcher in the service app that checks for changes to the setting file. Then if there are changes, it reloads the settings and carries on doing its thing,

The FileSystemWatcher class is very easy to use, to start a watch, add a sub to handle the Changed event:
Code:
Private Sub OnChanged(ByVal source As Object, ByVal e As IO.FileSystemEventArgs)
   'Put settings reload code here
End Sub
The start the watcher:
Code:
Public fsw_Settings As IO.FileSystemWatcher

Public Sub StartWatcher
   fsw_Settings = New IO.FileSystemWatcher

   fsw_Settings.Filter = "settings.ini"
   fsw_Settings.Path = Application.StartupPath 'May need '& "\"'
   AddHandler fsw_Settings.Changed, AddressOf OnChanged
   AddHandler fsw_Settings.Created, AddressOf OnChanged

   fsw_Settings.EnableRaisingEvents = True
End Sub

If you need any more help, just ask...
 
thanks, I realized that I'm only going to need an error condition flag, and the message associate with that. So, I am planning on setting a flag in the registry and a string int the registry by the service, and a timer in the tray icon app will check the flag and detect the error condition and basically turn the icon red indicating a problem. and then changing the tooltip to reflect the problem.

thanks for taking the time to consider a solution. I was reading about different kinds of interprocess communication to try to send more strings, but realized this will suffice.

cheers and I thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top