Windows Services and UI

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I would like to create a windows service that would expect an event from my
software to import data from a device and/or to import data in scheduled times

My questions are:
- How can I tell the windows service to import data from another application?
- Is it possible to have a UI for the service, like a tray icon with the
status of the service?

I never worked with services and I would like to have this information but I
can't find it.

I appreciate any kind of help like links, sample codes, etc...

The Best Regards
 
"Diogo Alves - Software Developer"
I would like to create a windows service that would expect an event from
my
software to import data from a device and/or to import data in scheduled
times

My questions are:
- How can I tell the windows service to import data from another
application?

That's not easy without cooperation from the other application. The
application should provide the data for the service to pick. For instance,
the application could periodically write a file to a pickup directory, and
the service would use a FileSystemWatcher to detect when a file appears
there. Or you could make the Service listen on a TCP Port (either at low
level using a socket, or by means of .Net Remoting), and then make the
application call into that port when it has some data for the service to
process. Or you can do it the other way round, implementing a remoting
listener in the application, and making the service call into the
application periodically.

- Is it possible to have a UI for the service, like a tray icon with the
status of the service?

Yes: Write a Windows application to provide the tray icon. This
application communicates with the service to provide status. Once more, you
will have to use some kind of interprocess communication to establish the
dialog between both programs (the windows app and the service).
If you need to send a small amount of data into the service, you can use
the ServiceController class to send an integer to the service. Anything
bigger than that has to be sent over some transort mechanism that you
program into both applications.
 
Fine... I can now manage my service with a application with the
serviceController...

Now here's the deal... Can I use a dll to comunicate with a device and
import his data with the service?

Everytime I try to do something in my service it says that the service work
is finished and is going to be stopped. :S

What I'm I doing wrong?
 
"Diogo Alves - Software Developer"
Now here's the deal... Can I use a dll to comunicate with a device and
import his data with the service?

Let's see if I understand: You wish to call a DLL from the Service, and
the DLL contains a function that returns some data. This should be perfectly
straightforward, nothing special to do in the service, just call the DLL as
you would call it from any other program.
Everytime I try to do something in my service it says that the service
work
is finished and is going to be stopped.

You must be doing something wrong. The service shoud have a method called
OnStart, which should configure and launch whatever the Service is going to
do and then terminate (leaving whatever you launched running in the
background). For instance, you could start a Timer inside the OnStart
method. Every time that the Timer event fires, inside the event you would
call your DLL, save the data, and exit from the event method. This will be
repeated periodically until you disable the timer, which you would do inside
the OnStop method of the service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top