Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Restricting DLL's to only one instance

Tags:

c#

.net

dll

I essentially want to make an api for an application but I only want one instance of that dll to be running at one time.

So multiple applications also need to be able to use the DLL at the same time. As you would expect from a normal api.

However I want it to be the same instance of the dll that the different applications use. This is because of communication with hardware that I don't want to be able to overlap.

like image 305
Danielhobby Avatar asked Sep 03 '26 00:09

Danielhobby


1 Answers

DLLs are usually loaded once per process, so if your application is guaranteed to only be running in single-instance mode, there's nothing else you have to do. Your single application instance will have only one loaded DLL.

Now, if you want to "share" a "single instance" of a DLL across applications, you will inevitably have to resort to a client-server architecture. Your DLL will have to be wrapped in a Windows Service, which would expose an HTTP (or WCF) API.

like image 173
Anton Gogolev Avatar answered Sep 05 '26 14:09

Anton Gogolev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!