Can a Singleton Class inside a DLL be shared across processes?

前端 未结 5 2094
眼角桃花
眼角桃花 2020-12-06 01:27

I am creating a custom .net hardware framework that will be used by other programmers to control some hardware. They will add a reference to our DLL to get to our hardware f

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 02:01

    Simply calling a singleton property in a different assembly from two different processes will create different instances of that class.

    But you can easily share information between processes using .Net Remoting, or fire interprocess events if you only need simple signaling (EventWaitHandle).

    [Edit:] To make it look like a Singleton to your callers, you can expose a class which will internally use Remoting to instantiate a singleton, and then return the instance transparently. Here is an example which (I think) does that: http://www.codeproject.com/KB/dotnet/remotingsingleton.aspx

提交回复
热议问题