473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2276
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be...
6
by: Bijesh | last post by:
Hi All, I've developed a Windows Service that acts as a remoting server (.NET Remoting). The client(user) is able to connect to the server and start a program by giving the executable path of...
5
by: pberna | last post by:
Dear all, I built a Web Form application to start and stop a Windows Service remotely. I successful tested the application on Windows 2000 server + IIS. I must include the ASPNET user to the...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
1
by: MAL | last post by:
Hello, I have 2 classes that work great as a windows app to retrieve and process data from an Oracle9i db. When I implement them in a Service program running as Local System, it fails on the...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
2
by: Dennis Stew | last post by:
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...
6
by: Jimmy | last post by:
Hi, I need to develop a secure Web Service that requires a username and password. One of the requirements is that the WS supports Windows Authentication, meaning accepts the username and...
7
by: HeatherS | last post by:
We are having issues with our windows services using memory and never releasing it. We have one service that has a file watcher which takes an xml file, inserts some records into a database, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.