none
How to create a Singleton and use it for multiple applications RRS feed

  • Question

  • I need to create a single instance of a class that implements a queue internally so that multiple applications can access the object to push items onto the queue. I know all about a Singleton class but nowhere in all of my reading have I seen it mentioned whether or not the Singleton would be available by different applications at the same time. I am aware of how to use a Singleton within an application, but not how to use one across applications.

    I would appreciate any help given.


    • Edited by JimNickFL Wednesday, December 9, 2015 6:33 AM clarify
    Wednesday, December 9, 2015 6:27 AM

Answers

  • Singleton can’t sync across applications. Each singleton will run in its own application space. Though it is possible to share a singleton amongst several processes via a technology that supports inter-process communication.

    If I understand your requirement correctly, implementing a Singleton doesn’t make sense.

    I would create a service and implement a thread safe queue.

    .NET has the ConcurrentQueue which “Represents a thread-safe first in-first out (FIFO) collection.”.

    https://msdn.microsoft.com/en-us/library/dd267265(v=vs.110).aspx


    william xifaras



    • Proposed as answer by William Xifaras Wednesday, December 9, 2015 8:06 PM
    • Edited by William Xifaras Wednesday, December 9, 2015 8:15 PM
    • Marked as answer by JimNickFL Thursday, December 10, 2015 1:05 PM
    Wednesday, December 9, 2015 8:02 PM

All replies