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...