Web Development

General discussion

.NET Global singleton class

Can I create a Singleton class in a global assembly that is shared among different processes? In other words, every process that has a reference to that library obtains always a reference to the same object when it instantiates such a class

I'm not sure offhand. But you can try declaring a static class inside a namespace (to be used in common by client assemblies/applications). Then, try to crunch out an assembly with this namespace code, and see if your compiler chokes.

If your tools let you do this, then try running two separate processes that import this namespace and utilize the static resource contained therein. Maybe try setting a property in one process, and getting it from the other, and see what kind of results you get. I could be wrong, but this might work.

Of course, being static, that would probably eliminate the whole instantiation aspect of the scenario, but you'd have your shared class, i suppose.

I think that when you pass an object by reference, even between assemblies, by default the references are talking about the same object, anyway, so you may not need to even try the static class thing, now that i think about it.

I don't think you can do this. because each process has its own memory space, so we get each singleton instance per process. However, in win32, you can have 2 processes share the same memory space, but it will be a different story.

Use shared memory technique to accomplish this

Until .NET 4.0, this is not available. But you can use native Win32 memory mapped file to accomplish this. Simply creating a static class in an assembly does not achieve sharing this resource across applications.

Start or search

Create a new discussion

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

Post type

Subject title

Topic Tags

Select up to 3 tags (1 tag required)

Cloud

Piracy

Security

Apple

Microsoft

IT Employment

Google

Open Source

Mobility

Social Enterprise

Community

Smartphones

Operating Systems

Windows

Mac

Malware

Tablets

Networking

Browser

Hardware

Software

Web Developerment

Linux

Off Topic

Message Body

Track this discussion and email me when there are updates

Please note: Do not post advertisements, offensive material, profanity, or personal attacks. Please remember to be considerate of other members. If you're new to the TechRepublic Forums, please read our TechRepublic Forums FAQ. All submitted content is subject to our Terms Of Use.