Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 20th, 2008, 6:26 PM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 292
Rep Power: 2 Jabo is on a distinguished road
Services in .NET programming

I have a program that I'm looking into converting the meat of the program into a service, and for two reasons: to free up the user interface while it's processing and so that it will run even if the pc is not logged in.

The part of the program I'm wanting to make into a service also emails and prints depending on options set in the user interface. Would this be impossible/impractical with the way my program is set up and would it pretty much take a whole rewrite of my program?
Jabo is offline   Reply With Quote
Old Sep 23rd, 2008, 9:54 PM   #2
MasterWill
C/C++ Developer
 
MasterWill's Avatar
 
Join Date: Sep 2008
Location: Florida, USA
Posts: 41
Rep Power: 0 MasterWill is on a distinguished road
Re: Services in .NET programming

Quote:
Originally Posted by Jabo View Post
I have a program that I'm looking into converting the meat of the program into a service, and for two reasons: to free up the user interface while it's processing and so that it will run even if the pc is not logged in.

The part of the program I'm wanting to make into a service also emails and prints depending on options set in the user interface. Would this be impossible/impractical with the way my program is set up and would it pretty much take a whole rewrite of my program?
I am in the process of designing a couple of services for the office to handle background data processing, so I am familiar with the dilemma. I wish that I could tell you that writing a service is straightforward, but having only used the express editions of VS I have found it to be a bit of a pain; not impossible, but not as simple as I would like. If I am not mistaken, the purchased VS editions have templates for Windows services, so that should get you to at least a starting point.

As for requiring a whole rewrite, I guess that would depend on how much your classes are tied into your GUI. If they are loosely coupled it should be relatively easy to pull them out and put them into a service EXE.

The problem that I am trying solve at the moment is to how to communicate with the service and where to put the configuration settings. I have a feeling that I will wind up using some sort of named pipes or TCP connection, but I have been looking into COM+/DCOM as the communication channel and have had nothing but headaches so far. I guess WCF could be an option as well, but I am not familiar at all with that.

I would suggest if you do separate the logic out into a service, look into using BackgroundWorker objects for handling the emailing and printing functions. They are easier to work with than threads (they actually encapsulate background threads) and only require overriding a couple of methods. Depending on how much these functions do, you may even want to separate them into their own services as well; overkill for simple stuff, but more robust for complex spooling solutions.

Glad to help if you want to bounce ideas around; would help me out as well.
__________________
-- William
MasterWill is offline   Reply With Quote
Old Sep 23rd, 2008, 11:17 PM   #3
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 292
Rep Power: 2 Jabo is on a distinguished road
Re: Services in .NET programming

The emailing and printing is just an after-effect of the part I'm wanting to make into a service. The first part runs through completely, then, depending on results and settings, will email and/or print the results. At present, the results are displayed in a textbox and also saved to a text file. If there were any problems, an errstring is built with all bad results, and if the errstring is not blank at the end of the run, it's emailed/printed.

From what I've read about services so far, they can't communicate with the GUI, and the only control you have over the service is stopping, starting, pausing, loading and unloading. There has to be a way to get the settings to the service, though. Probably an ini file that is registered with the pc through the registry, I'm guessing. The service can't interact with the user space at all.
Jabo is offline   Reply With Quote
Old Sep 24th, 2008, 10:21 AM   #4
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
Re: Services in .NET programming

How about the client server model. Where you have the services as the server and the UI as the client.
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Sep 24th, 2008, 1:59 PM   #5
MasterWill
C/C++ Developer
 
MasterWill's Avatar
 
Join Date: Sep 2008
Location: Florida, USA
Posts: 41
Rep Power: 0 MasterWill is on a distinguished road
Re: Services in .NET programming

Quote:
Originally Posted by kruptof View Post
How about the client server model. Where you have the services as the server and the UI as the client.
Love your quote line, BTW ...

That's basically what I was getting at was some sort of client-server design. The question is, what communication type to use: sockets, pipes, CORBA, COM, WCF, etc. Obviously there are a million and one ways to do any task, but getting the most efficient one is the trick.

As for the settings being in an INI file or registry key, that's a fast way to set it up and very easy to modify. I was thinking more along the lines of having a way to tell the service to re-read those settings without having to do a restart of the service ... basically a SIGHUP, to use a more unix-like way of describing it. Having to do a service restart is not unacceptable, but it would be nicer to be able to signal the service somehow that you made changes to its configuration, and to reload the settings at the next available interval. For example, your service is in the middle of processing a large quantity of data. You make some changes to the INI file or the registry and you want the service to reload its settings before starting on the next dataset. Do you want to have to stop the service (and wait for it to finish what it is doing) and then restart it? What happens if you stop the service and it has not completed the dataset it was processing? The new settings will be read when you restart it - are these the correct settings for the incomplete dataset? It would be smoother and, IMHO, more elegant to tell the service to schedule a reload of the settings and allow it to handle that reload as part of its natural processing scheme.
__________________
-- William
MasterWill is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming without post secondary education Eric the Red Other Programming Languages 6 Mar 7th, 2006 6:56 PM
Does Programming Make You Smarter? Sane Coder's Corner Lounge 43 Oct 2nd, 2005 7:12 AM
MIT's Metaphor For Software Programming Infinite Recursion Other Programming Languages 2 Jun 12th, 2005 7:42 AM
Problems with C programming in Visual Studio .NET 2003 debugger1 C 4 Jun 3rd, 2005 8:03 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC