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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB .NET Windows Application as Windows Service

Status
Not open for further replies.

jgobrien

Programmer
Apr 15, 2005
27
0
0
US
I recently created a typical windows application project in VB .NET. It has a main form and a tray icon. I would like to give some end users the ability to install this application as a windows service.

The application's main purpose is to monitor XML messages and make changes to a SQL server database. The main form is an essential part of the application because it will be used to monitor events.

I did some research and found tons of information about creating a windows service project in VB .NET, but they don't seem to have the ability to use windows forms or any real user interface controls.

I was wondering if and how I could install this application as a windows service without using SRVANY. I tried adding a ServiceInstaller and ServiceProcessInstaller control to the main form and configured my installer as if this were a windows service project, but it did not work.

Any ideas?
 
What exactly do you mean by:

Code:
The main form is an essential part of the application because it will be used to monitor events.

Would it be possible to move those monitors into a GUIless class?

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I would rather not store all events and monitor them with a seperate application or viewer. It is much easier right now to simply scroll them into a listview.
 
Easier yes, but you can't use it for a service. Build a text/log file manager and store the entries there. Or in a database, or even another XML file. If you want, you could event create a new app that had a list box and could view those entries.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
As Rick suggested, you'll need to move user interfaces to a separate application. Your service will need to be free of user interfaces.
 
So maintain the app, but remove the "working" code. Set it up to read from text/xml files. Have it save the prefrences/settings to another XML file. Then take the "working" code and have it write to the text/xml files, and get its' settings from the other XML file.

If you want it to run as a server, the GUI needs to be removed. And it's a nice looking GUI, so I'd say hang onto it.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Either that or I will have to use SRVANY.
 
Yeah, I would like to avoid a complete redesign. It's hardly worth it just so I can have it run as a real service.

I would need to create some sort of a communication interface between the service and the GUI so that I could send and possibly receive commands and events from it in realtime.

Only problem with SRVANY is that I can only have a GUI available if it is running under the LocalSystem account. (Allow desktop interaction)

The LocalSystem account will limit my ability to connect to an external SQL server database.
 
but they don't seem to have the ability to use windows forms or any real user interface controls.
This is because services must not have any user interface.

Services start when the machine boots, not when a user logs in. At boot time, there is no desktop available for displaying a user interface. So, no Forms or MessageBoxes can be used in your service.

If you have a need for configuring your service, then create a small application to do this, and use remoting to pass the info to the running service.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Well actually, they CAN have user interfaces, but ONLY if running under "Local System" with the "Allow Desktop Interaction" box checked. Before logging in, any screen elements of the service are hidden. (similar to the effect achieved when 'locking' your system)

I just set it up my application to run as a windows service using SRVANY. And configured it to run as a "Local System" service with "Allow Desktop Interaction" checked, and it is working completely.

I thought my connections would be blocked if the service wasn't running as a "Network Service", But apparently that is not the case.
 
My two cents...

I'd stick to Best Practices and create a new service that has no UI. Have users use the Interface you already have to update a DB with those settings and have the service check that DB for settings it needs to function. You could set it to check the DB when it starts or on an interval with a timer.

This method also allows for greater scalability.



--
James
 
Yeah, but when you press a button, it should do an instant check for messages, with an immediate response in the console about the event. (Much like an email client) Everything would be slow and unresponsive using a queue solution.

As far as scalability is concerned, There is really only once instance of this application per network.
 
Everything would be slow and unresponsive using a queue solution.

Not really. If you used Chiph recommendation of remoting to access the service directly, running the process would be almost instantanious. Having the service update a database, XML or flat file could also be extremely fast given that you are just pushing data, no pull or waiting for feedback. And the app itself would just need to requery or refresh it's data, probrably the slowest step of the process, but provided you are just pulling in a simple table from a database, or querying an XML file, it shouldn't take long. The whole process should be able to run in under a second, depending on the network.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Generally, it's a lot of additional work, and I dislike using timers for that sort of syncronizing. It will be difficult at best to make things as responsive as they are now. Especially with the refreshing of the event log (instead of just appending to it). I will need to try and predict how long it will take for an event to execute, and then force a refresh of the event log accordingly.

I can see many situations where your suggestions would be the better solution, but considering what my application will be used for, I find it unnecessary.

In my mind, I don't see any reason why services shouldn't be able to have user interaction.

All I want is to have my application start up as a tray icon before the user logs in.
 
sounds like a complete thread. Could someone enlighten me on what SRVANY is. Thanks
 
Everything would be slow and unresponsive using a queue solution.
Actually, I've seen over 100 somewhat large XML messages sent per second over MSMQ. Remoting is faster, of course, but MSMQ is not a dog like many people think it is.

We actually filled up a MSMQ once (cluster failed to failover). 3.6 gigabytes worth of messages were held without loss, right up until we hit the hard limit, and NetIQ started screaming for the engineering support staff to come look at it... ;-)

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
When I said "Everything would be slow and unresponsive using a queue solution," I meant that my user interface might become slow and unresponsive if I was dumping requests into a database or message queue.

I say this because my service would be checking those queued requests on a timer, and also my event viewer would be refreshing on a timer. (at least that's how I pictured it)

Basically, user-driven events wouldn't necessarily appear instantaneous to the user.

The remoting is probably the best solution for most people.

However, SRVANY is working out very well for me. My service loads and connects before user logon and begins doing its job. When the user logs in, the tray icon becomes visible and the main user interface can be opened. I will be sure to post if I have any problems with it in the future.

I thank everyone for their suggestions. I will keep them all in mind when starting my next project.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top