0

Consider this case: I have WCF service which will create an object only once (InstanceContextMode:=InstanceContextMode.Single) for all clients. This works fine. This object is a complex object and functioned as a processor. So I need the same object instance to be accessed by my other application under same windows machine, which can be a winform or a windows service. By doing this, I do not need to create a new object for every other application and just use the same object which WCF has create before. How to get it done?

I have read singleton pattern, but it seems just work within single application, or am I wrong?

Buzz
  • 321
  • 2
  • 3
  • 20
  • 1
    Each executable/process runs in its own allocated memory. To share data between multiple processes you can use memory-mapped files. To perform locking you can use a mutex or sempahore. But you must have a good reason why ever you want to do that. Maybe you should re-look at your design and what you want to accomplish by sharing data between 2 processes. –  Feb 10 '15 at 05:26
  • Following on from @Neills comment, regarding the use of Singleton WCF, read this post: http://stackoverflow.com/a/1756505/569662 - I would avoid at all costs. – tom redfern Feb 10 '15 at 08:45
  • Here my case: I have an object which has database. This object should be run in single instance and perform device discovery and other things including update it's database. This object has public methods & event. This object should run when computer start and only will off when computer shutdown. I need other clients communicate to this object so I create WCF service. This object also should can be accessed by any other application which I will develop whether for now or future. Somehow I think I will create a windows service to host this object. Separate WCF service will access it. Cntinue.. – Buzz Feb 11 '15 at 07:21
  • But some user saying why do I need create another windows service if I can have the WCF service hosted in IIS server and run the object? So at the end I create WCF service and to create this object. I set the WCF instancecontextmode to single to make sure this object only initialized once and not being call everytime request made. This works good. But I have another problem. I need my other application can access this object. 2 solution: create new object or use the same instance. Continue below.. – Buzz Feb 11 '15 at 07:28
  • I'd prefer to use the same instance if possible, to make the object persistent and not consume more memory. And because there will be more other application need to access the obejct. I'd like to avoid create another object since if I have 5 application it means it will create another 5 object. And since this object act like a processor and make updates to its database, I am afraid multiple object will mess it up. I welcome any suggestion and recommendation. Thanks. – Buzz Feb 11 '15 at 07:29

0 Answers0