471,339 Members | 1,246 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Windows Service access to variables/properties By Client Applicati

How do I access Public variables within a Windows Service?

I can, and have, created installed and executed a basic Service. From my
client App I can Start, Stop...etc the service.... What I want to do is to
read properties that are in the service. for instance if the service had a
Propertie or Public variable like

Public Int Myint = 12; (or... Public Myint as integer = 12)
Then how could I read that variable from a typical windows Form application?

The basic Idea is to have a service churning away all the time and then when
a client app OR mulitple client apps need info that the service is
calculating then the client app should be able to simple reference the
variable and read it .... no?


Jul 22 '05 #1
2 2174
On Thu, 14 Jul 2005 17:08:01 -0700, Dennis Stew wrote:
How do I access Public variables within a Windows Service?

Public Int Myint = 12; (or... Public Myint as integer = 12) Then how could I read that variable from a typical windows Form application?
You can't. A windows service is almost just a normal application except
that it runs in the background and has no UI. You can't access variables
from another application just like that. That would be too easy :-)
The basic Idea is to have a service churning away all the time and then when
a client app OR mulitple client apps need info that the service is
calculating then the client app should be able to simple reference the
variable and read it .... no?


No. An easy enough solution (among others) would be to expose an object
from your Windows Service through .NET Remoting. Your client applications
would then just need to connect to your .NET Remoting server and call
methods of the exposed object. These methods can return whatever values
they want. You effectively end up with a Client/Server system. Have a look
on the Web for .NET Remoting, there are loads of articles and tutorials to
do just what you want. Or get the excellent Ingo Rammer's book: Advanced
..NET Remoting.

Other than that, you could build a similar system but using raw sockets
instead of .NET Remoting (although i don't really see why you would want to
do that), use shared memory (that will require you to use the Win32 API
through interop since there are no .NET wrappers for this yet), have your
service write a file and your client applications read this file...
Jul 22 '05 #2
That would be crossing the app domain at run-time.
I believe you can do this but it isn't recommended and
can be a bit complex to implement reliably.

I think what a lot of people do is have the service
listen on a TCP socket. Your client apps would
open the socket, send a message, the service responds
back on the socket.

This should prove useful:

http://www.eggheadcafe.com/articles/20020323.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Dennis Stew" <Dennis St**@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
How do I access Public variables within a Windows Service?

I can, and have, created installed and executed a basic Service. From my
client App I can Start, Stop...etc the service.... What I want to do is to
read properties that are in the service. for instance if the service had
a
Propertie or Public variable like

Public Int Myint = 12; (or... Public Myint as integer = 12)
Then how could I read that variable from a typical windows Form
application?

The basic Idea is to have a service churning away all the time and then
when
a client app OR mulitple client apps need info that the service is
calculating then the client app should be able to simple reference the
variable and read it .... no?

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark | last post: by
6 posts views Thread by Jimmy | last post: by
7 posts views Thread by HeatherS | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.