Interacting with a service?

  • Thread starter Thread starter derek
  • Start date Start date
D

derek

Hey,

I'm trying to build a component that satisfies the
following properties:

1) only one component is ever created and it maintains
its state
2) it can be accessed by any thread on the local machine
simultaneously (I will do the synchronization myself
since I want read/write locks)
3) the component is never deleted
4) I need to call some of its methods

It seems like component services are the way to go (or
maybe Windows services?) but I can't figure out how to
keep the component alive without using JITA. And if I use
JITA, synchronization is done for me. And if I use a
Windows service, I don't seem to be able to call methods
on it.

Any suggestions of resources or ideas I can investigate?
Thanks in advance.
 
You will need a combination of a few items. As for a component that is
created and maintains state, the singleton pattern is rather nice. Having to
contact the component from a variety of apps and threads dictates a service
of some sort (for ease of set up, although there are other ways to tackle
this).

One thing to note: If the component is not constantly accessed, you can use
some sort of store to store the state of the object (serialization, for
example) and instantiated when necessary. For an object accessed a lot of
times on a regular basis, a service might be a better option.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Hi,

Probably you can look at creating a singleton object.
This can be acheived either using a factory to create a
object or using the remoting framework. Using remoting
framework you can create singleton objects and also
manage the life time of the object.

You can refer to the following articles on creating
singleton object and manage life time.

http://samples.gotdotnet.com/quickstart/howto/doc/Remoting
/singleton.aspx

http://msdn.microsoft.com/msdnmag/issues/03/12/LeaseManage
r/default.aspx

Hope this helps...

Regards,
Madhu

MVP | MCSD.NET
 
Thank you both for the help. The component will be
accessed many times so the serialization idea, won't work
here. The singleton object would be perfect though.

I am thinking of making my component a Windows service.
So basically, I need to figure out how to call methods on
this service so that different threads on the machine can
ask it for info.

Does anyone have a code sample/reference for this type of
thing?
 
Back
Top