Multiple programs using the same DLL - will Singleton work?

  • Thread starter Thread starter Anders Eriksson
  • Start date Start date
A

Anders Eriksson

I have a dll that contains a class which is a singleton.

If multiple programs use this dll and the class, will the singleton work?
I.d. Will I only get one object or will each program have its own object?

// Anders
 
I have a dll that contains a class which is a singleton.

If multiple programs use this dll and the class, will the singleton work?
I.d. Will I only get one object or will each program have its own object?

I believe each program will run in its own AppDomain, and therefore the DLL
will be loaded into each AppDomain, so there will be multiple copies of the
object.
 
I believe each program will run in its own AppDomain, and therefore the DLL
will be loaded into each AppDomain, so there will be multiple copies of the
object.
Thna you Jeff!

Is there anyway of making a singleton that only creates one object even
if multiple program is using it?

// Anders
 
No, not really. Not in .NET, and even in unmanaged, native Win32
programs, not without a significant amount of trouble.

However, it's very likely that you don't really want a singleton object
per se anyway, but rather simply some way of controlling access to a
shared resource across multiple processes.

There are a number of good techniques for approaching that kind of
problem, so if you can describe more specifically what it is you're
really trying to do (i.e. don't ask about some specific implementation
you've already decided on, but rather ask about the actual goal you're
trying to solve), you'll likely get good advice along those lines.

Pete

I will try ;-)

I have a COM Server that my class/dll connects to. According to the
people that have made the COM Server it's undefined how it will act if
multiple clients connects to the server.

Now we need to have to programs/clients use this COM Server. Since I
have put my client into a dll, hence my question.

I'm feel like the best solution would be that the COM Server could
handle multiple clients, but I have no saying on this and the creators
seems unwilling to explore this...

So if there is some other way I would really appreciate it!

// Anders
 
Back
Top